规范的第3.5.4节规定:"ElementType []形式的数组类型等同于具有索引签名[index:number]的对象类型:ElementType"但这似乎不是这种情况,例如
var a: {[index: number]: string;};
var b: string[];
a = ['1','2']; // ERROR: Cannot convert 'string[]' to '{ [index: number]: string; }'
b = ['1','2']; // OK
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?
当.d.ts
使用import x = require('...')
模式导入typings()文件时,使用package.json typings
条目时语义会发生变化
.
例如,如果未使用package.json typings
条目,则会成功导入以下声明文件,但Exported external package typings file is not a module
在与typings
条目一起使用时会生成错误TS2656():
declare module 'mymodule' {
export function myfunc(source: string): string;
}
Run Code Online (Sandbox Code Playgroud)
declare module {}
当与package.json typings
条目一起使用时,同一文件减去导入成功,但Cannot find module
在没有typings
条目的情况下使用时会生成错误TS2307().
export function myfunc(source: string): string;
Run Code Online (Sandbox Code Playgroud)
为什么语义的变化?
看起来如果你使用新的npm typings功能,你将必须维护你的打字文件的npm和非npm版本.
我试图在项目本身中使用项目打字文件时遇到这个问题(TypeScript没有在当前项目的package.json中查找typings
条目,它似乎限制了它的搜索./node_modules
).
使用TypeScript 1.7.5进行测试.
下面的测试尝试运行 less pager 命令并在用户退出后返回。问题是它不等待用户输入,它只是列出整个文件并退出。平台:xubuntu 12.04,Dart 编辑器版本:13049。
import 'dart:io';
void main() {
shell('less', ['/etc/mime.types'], (exitCode) => exit(exitCode));
}
void shell(String cmd, List<String> opts, void onExit(int exitCode)) {
var p = Process.start(cmd, opts);
p.stdout.pipe(stdout); // Process output to stdout.
stdin.pipe(p.stdin); // stdin to process input.
p.onExit = (exitCode) {
p.close();
onExit(exitCode);
};
}
Run Code Online (Sandbox Code Playgroud)
以下 CoffeeScript 函数(使用 Nodejs I/O)有效:
shell = (cmd, opts, callback) ->
process.stdin.pause()
child = spawn cmd, opts, customFds: [0, 1, 2]
child.on 'exit', (code) ->
process.stdin.resume()
callback code
Run Code Online (Sandbox Code Playgroud)
我怎样才能在 …
在资源管理器中单击文件会在当前编辑器选项卡中将其打开,而不是打开新的编辑器选项卡。这有效地将打开的选项卡的数量限制为单个选项卡。如何更改此行为,以便在资源管理器中单击以在新选项卡中打开文件?
使用文件->打开文件... Ctrl + O菜单命令可以按预期工作,并在新的编辑器选项卡中打开文件。
观察到: