【发布时间】:2022-01-20 02:46:54
【问题描述】:
我对 typescript 中的 type 关键字有疑问。
你可以看到下面的代码。
参数必须在前缀中包含单词 ('api')。
当然,我可以使用indexOf等编码进行检查。
但我只想使用 type 关键字。
interface SomethingParam {
url: string
}
function check(url: SomethingParam) {
console.log(url);
}
check({ url: 'foobar' }) // error
check({ url: 'api/foobar' }) // ok
【问题讨论】:
标签: typescript typescript-types