Here is an issue with the code snippet below:
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'.
An alternative solution would be:
type char = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | string;
However, this approach presents two problems:
Upon hovering over a
char
variable, the tooltip incorrectly displays its type asstring
and notchar
(observed in VSCode). Even if the'a' | 'b' | 'c'
, etc., values were included, the tooltip text remains unchanged.No warning is generated when attempting something like
const letter: char = 'notachar'
;