Seb*_*ald 5 declaration typescript tsd
我想创建一个接口,其中属性可以是a string或Function必须返回a string.我目前有以下内容:
interface IExample {
prop: string|Function;
}
Run Code Online (Sandbox Code Playgroud)
但这对我来说并不明确,因为Function它可以归还任何东西.我想告诉编译器返回值必须是a string.
这怎么可能在Typescript?或者它可能吗?
TSV*_*TSV 11
type propType = () => string;
interface IExample {
field : string | propType;
}
class MyClass1 implements IExample {
field : string;
}
class MyClass2 implements IExample {
field() {
return "";
}
}
Run Code Online (Sandbox Code Playgroud)
type PropertyFunction<T> = () => T;
interface IExample {
field : string | PropertyFunction<string>;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4059 次 |
| 最近记录: |