【发布时间】:2022-12-12 23:24:17
【问题描述】:
让我们考虑例子
type Routes = 'first' | 'second';
type BeforeSign = //...
const handleRoute = (route: BeforeSign<Routes, '#'>) => route;
handleRoute('first');
handleRoute('first#additional');
handleRoute('first#random');
handleRoute('second#example');
// @ts-expect-error
handleRoute('third');
// @ts-expect-error
handleRoute('third#nope');
如何编写BeforeSign泛型类型来使所有handleRoute调用都没有错误?
【问题讨论】:
标签: typescript generics