我想在 TypeScript 中创建两个类型,它们都是一个数字:
export type GlobalPortIndex = number;
export type TypePortIndex = number;
据我所知,TypeScript 会认为它们相互兼容,因为它们完美重叠。
但我希望它们不兼容,所以当我输入 GlobalPortIndex
时,如果我尝试为其分配 TypePortIndex
,我会收到类型错误.这是为了确保我不会在代码中混淆它们,例如,我不能将一个传递给需要另一个的函数。
有什么 TypeScript 技巧可以实现这一点?