小编cod*_*tix的帖子

TypeScript项目的目录结构

什么是TypeScript项目的惯用目录结构?

我希望在这样的结构中具有以下特征:

  1. TypeScript源代码和转换的JavaScript的单独目录
  2. 项目源代码和测试代码的单独目录
  3. 解决跨测试和源代码的引用的机制.

directory-structure conventions typescript typescript1.8

26
推荐指数
2
解决办法
2万
查看次数

从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)

javascript arrays typescript

8
推荐指数
1
解决办法
999
查看次数

TypeScript默认导入失败

我正在尝试设置一个项目并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: …

javascript module typescript typescript1.8

7
推荐指数
1
解决办法
889
查看次数

Node.js Global eval,抛出ReferenceError

我正在尝试从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)

javascript scope eval node.js ecmascript-5

6
推荐指数
1
解决办法
2332
查看次数

无法修改React DevTools for Chrome的组件道具

我正在开发一个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

5
推荐指数
1
解决办法
3156
查看次数

如何全局安装 Dart 包?

Pub Package Manager 是否提供了全局安装包的方法?

我担任 Node.js 开发人员已经有一段时间了,我想知道是否有pub相当于npm install -g <package_name>

如果有办法全局安装软件包,是否有办法注册二进制脚本,可以像 shell 命令一样安装并调用这些脚本。

dart dart-pub

4
推荐指数
1
解决办法
3502
查看次数

如何在没有继承的情况下使用Mixins?

是否可以将mixin应用于类而不从目标类继承任何其他类?例如,我可以实现以下内容:

class User with Persistence {
  // implementation
}
Run Code Online (Sandbox Code Playgroud)

您在飞镖中的大多数Mixins示例似乎都与继承相结合.

提前致谢!

mixins dart

3
推荐指数
1
解决办法
123
查看次数