这个 typescript 方案是什么意思?
interface Validator<T extends FormControl> {
(c:T): {[error: string]:any};
}
我对 Typescript 有点陌生,我想了解这个接口(interface)函数。特别是,<T extends FormControl>
是什么意思?代表?
还有什么{[error: string]:any}
表示?我的猜测是该函数的返回对象是一个具有“string”类型键和“any”类型值的对象。有人可以帮忙澄清一下吗?
最佳答案
what does the
T extends FormControl
represent
这是 generics .基本上是 <T extends FormControl>
介绍一种新类型 T
那应该是 FormControl
的子类型类型。
Validator
是一个函数,它接受作为 FormControl
的子类型的任何类型的对象, 包括 FormControl
类型。
what
{[error: string]:any}
signify?
它指定了一个新的 indexable type具有字符串类型的属性。
关于javascript - 这个 typescript 方案是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46935568/