Types 在打字文件中用空格声明函数
在Types 在打字文件中用空格声明函数,types,typescript-typings,.d.ts,Types,Typescript Typings,.d.ts,在.d.ts文件中是否有一种格式来声明名称中带有空格的函数 以下形式的事物: export namespace Foo { function "foo bar"(): void; } 不能直接用空格创建函数声明。您可以使用名称空间类合并来实现您想要的: export class Foo { private constructor() { } // so nobody acidentaly instantiates this static ["foo-bar"] = functi
.d.ts
文件中是否有一种格式来声明名称中带有空格的函数
以下形式的事物:
export namespace Foo {
function "foo bar"(): void;
}
不能直接用空格创建函数声明。您可以使用
名称空间类
合并来实现您想要的:
export class Foo {
private constructor() { } // so nobody acidentaly instantiates this
static ["foo-bar"] = function (): void {
}
}
export namespace Foo {
export function other() {
}
}
Foo.other() // ok
Foo["foo-bar"]() // ok
注意:在新代码中避免使用名称空间,而是使用模块。名称空间和模块之间有什么区别?
namespace
是用于代码分离的旧TS构造。模块(不要与ts中的module
关键字混淆)是组织代码的标准ES2015方式谢谢,我假设.d.ts
文件的正确语法是:静态[“foo bar]:()=>无效代码>?