什么是TypeScript项目的惯用目录结构?
我希望在这样的结构中具有以下特征:
我在下面的代码中做错了什么?
我试图扩展Array我的课程MyNumberList,然后尝试使用它.我看到的是,似乎没有任何项目被添加到列表中.undefined当我尝试访问列表元素时,我得到了一个.
PS我正在使用TypeScript 1.8.2
class MyNumberList extends Array<number> {
constructor(...numbers: number[]) {
// looks like this is not working
super(...numbers);
}
}
let statusCodes: MyNumberList = new MyNumberList(10, 20, 30);
console.log(statusCodes[0]); // printing undefined
console.log(statusCodes.length); // printing 0
Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个项目并mocha使用mjackson/expect库运行测试以进行断言.我要测试的代码是:
// inside src/lib/math.ts
export function sum(a: number, b: number): number {
return a + b;
}
Run Code Online (Sandbox Code Playgroud)
我的测试如下:
// inside src/tests/math.tests.ts
/// <reference path="../../typings/main/ambient/mocha/mocha.d.ts" />
/// <reference path="../../typings/main/ambient/expect/expect.d.ts" />
import expect from 'expect';
import {sum} from '../lib/math';
describe('sum', () => {
it('should add two numbers', () => {
expect(sum(1, 2)).toEqual(3);
});
});
Run Code Online (Sandbox Code Playgroud)
我可以使用以下命令使用tsc编译代码:
find src -name *.ts | xargs tsc --declaration --sourceMap --module commonjs --target es5 --listFiles --outDir .
但是当我mocha使用以下命令从项目目录运行时:
mocha tests
我在测试中看到以下错误:
TypeError: …
我正在尝试从Rhino书中学习JavaScript.我试图从书中执行以下代码eval().我使用node.js(v0.10.29)来执行示例.
var geval = eval; // aliasing eval to geval
var x = 'global'; // two global variables
var y = 'global';
function f () {
var x = 'local'; // define a local variable
eval('x += "changed";'); // direct eval sets the local variable
return x;
}
function g () {
var y = 'local'; // define a local variable
geval('y += "changed";'); // indirect eval sets global variable
return y;
}
console.log(f(), x); // => expected …Run Code Online (Sandbox Code Playgroud) 我正在开发一个React应用程序并设置webpack将我的代码打包成捆绑包.
但是,当我使用React DevTools在Chrome中加载我的应用程序并尝试通过扩展修改组件的道具时,它不会更改值或使用新值重新渲染.
以下是我的 webpack.config.js
'use strict';
const webpack = require('webpack')
module.exports = {
entry: {
agile: './client/js/agile.jsx.js',
vendor: [
'domready',
'react',
'react-dom',
'classnames'
]
},
output: {
filename: '[name].bundle.js',
path: 'public/js',
publicPath: '/js/'
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel' }
]
},
plugins: [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(true),
new webpack.optimize.CommonsChunkPlugin({names: ['vendor'], minChunks: Infinity}),
new webpack.HotModuleReplacementPlugin()
],
target: 'web',
devtool: 'source-map',
stats: {
color: true,
modules: false,
reasons: false
},
devServer: {
hot: true, …Run Code Online (Sandbox Code Playgroud) google-chrome-devtools reactjs webpack webpack-dev-server webpack-hmr
Pub Package Manager 是否提供了全局安装包的方法?
我担任 Node.js 开发人员已经有一段时间了,我想知道是否有pub相当于npm install -g <package_name>
如果有办法全局安装软件包,是否有办法注册二进制脚本,可以像 shell 命令一样安装并调用这些脚本。
是否可以将mixin应用于类而不从目标类继承任何其他类?例如,我可以实现以下内容:
class User with Persistence {
// implementation
}
Run Code Online (Sandbox Code Playgroud)
您在飞镖中的大多数Mixins示例似乎都与继承相结合.
提前致谢!
javascript ×3
typescript ×3
dart ×2
arrays ×1
conventions ×1
dart-pub ×1
ecmascript-5 ×1
eval ×1
mixins ×1
module ×1
node.js ×1
reactjs ×1
scope ×1
webpack ×1
webpack-hmr ×1