I have a question about type keyword in typescript.
you can see the below code.
the argument has to include the word ('api') in the prefix.
of course, I can check it using coding such as indexOf
.
but I want to use the type keyword only.
interface SomethingParam {
url: string
}
function check(url: SomethingParam) {
console.log(url);
}
check({ url: 'foobar' }) // error
check({ url: 'api/foobar' }) // ok
CodePudding user response:
you can try like it
function check(url: `api/${string}`) {
console.log(url);
}
check('foobar') // error
check('api/foobar') // ok