
Typescript에서 리터럴 타입을 사용한 트릭으로 유용하게 사용할 수 있는 기능입니다.
TypeScript의 리터럴 타입은 string, number 두 가지가 있으며 이를 사용하여 문자열이나 숫자에 정확한 값을 지정할 수 있습니다.
string 리터럴 타입과 string, number 리터럴 타입과 number 타입을 union type으로 만들 경우 추천 코드에 리터럴 값이 노출되면서 string, number 타입도 함께 사용할 수 있습니다.
type LiteralWithString = 'wow' | 'amazing' | (string & {});
let exA:LiteralWithString = 'wow';
let exB:LiteralWithString = 'any string';
let exC:LiteralWithString = 1; // Type 오류
코드 추천에서 string 리터럴로 지정한 wow amazing이 추천 목록에 노출됩니다.

type LiteralWithNumber = 1 | 2 | (number & {});
let ex1:LiteralWithNumber = 1;
let ex2:LiteralWithNumber = 9999;
let ex3:LiteralWithNumber = ''; // Type 오류
코드 추천에서 number 리터럴로 지정한 1 2가 추천 목록에 노출됩니다.
