string을 다이나믹하게 type checking 하려고 했다가.. 신기한거 많이 배웠다
Documentation - Narrowing
Understand how TypeScript uses JavaScript knowledge to reduce the amount of type syntax in your projects.
www.typescriptlang.org
Checking validity of string literal union type at runtime?
I have a simple union type of string literals and need to check it's validity because of FFI calls to "normal" Javascript. Is there a way to ensure that a certain variable is an instance of any of ...
stackoverflow.com
typescript를 열심히 배우자..
아래가 젤 나은 듯하다. type category 개수가 작으면 union으로 아니면 array로 하는 게 좋은데 나는 몇 개 없어서 아래와 거의 유사하게 해줬다.

https://engineering.linecorp.com/ko/blog/typescript-enum-tree-shaking
TypeScript enum을 사용하지 않는 게 좋은 이유를 Tree-shaking 관점에서 소개합니다.
들어가며 안녕하세요. LINE Growth Technology UIT 팀의 Keishima(@pittanko_pta)입니다. 이번 글에서는 TypeScript의 enum을 사용하지 않는 편이 좋은 이유를 Tree-shaking 관점에서 소개하겠습니...
engineering.linecorp.com
hasOwnProperty
Narrowing Down Union Types
TypeScript offers powerful features for narrowing down branches when working with third party APIs or functions that support data in different forms.
www.totaltypescript.com
'TIL' 카테고리의 다른 글
타입스크립트에서 상수를 안전하게 쓰는 법 (0) | 2024.02.26 |
---|---|
Presentational and Container 패턴과 리액트에 대한 고찰. (0) | 2024.02.15 |
업무 중 참고한 사이트 01.26 (0) | 2024.01.29 |
업무 중 참고한 사이트 1.29 (0) | 2024.01.29 |
업무 중 참고한 사이트 01.26 (0) | 2024.01.26 |