[英]How to override VSCode tooltip for TypeScript type alias?
以下代码不起作用:
type char = 'a' | 'b' | 'c' | 'd' | 'e' | 'f';
const s: string = 'foo';
const [c]: char = s;
// [ERROR]: Type 'string' is not assignable to type 'char'.
我可以这样做:
type char = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | string;
但这会导致两个问题:
如何覆盖 TypeScript 类型别名的 VSCode 工具提示?
当您有一个可以解决更简单问题的联合时, TypeScript 将始终显示更简单的版本
例子:
type char = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | string;
// resolves to the following simpler type so that is what TypeScript will show.
type char = string;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.