是否可以使用打字稿中的关键字类型检查句子是否包含某个单词?

is it possible to check if the sentence include a certain word using keyword type in typescript?

我对 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

你可以试试

function check(url: `api/${string}`) {
  console.log(url);
}

check('foobar') // error
check('api/foobar') // ok