본문 바로가기
Programming Step/Typescript3
Index Signature, 제네릭 keyof 제네릭과 keyof 를 사용한 경우 function test(a:T,b:U){ return "aaaa "+a[b] } test({name:"test"},'name') Index Signature를 사용한 경우 Index Signature는 객체가 형식이며, 객체의 타입을 명시해야 하는 경우 사용할 수 있습니다. interface testType { [key: string]: string } function test2(a:testType,b:string){ return "aaaa "+a[b]; } test2({name:"test"},'name') 2022. 6. 29.
typescript string literal 과 string enums의 차이 literal 과 enum의 차이는 javascript로 변환했을 때 코드의 유무 입니다. Typescripts Transpiler는 코드를 변환하는 동안 type 확인을 위해서만 사용하기 때문입니다. 다만 대용으로 const를 enum 앞에 붙여 const enum 형식으로 사용하면 타입 확인에만 사용할 수 있습니다. typescript 예제 코드 // 리터럴 타입 type MyKeyType1 = 'foo' | 'bar' | 'baz'; // enum 타입 enum MyKeyType2 { FOO = 'foo', BAR = 'bar', BAZ = 'baz' } // const를 사용한 enum 타입 const enum MyKeyType3 { FOO = 'foo', BAR = 'bar', BAZ = 'ba.. 2022. 6. 29.
typescript express --files 옵션 tsconfig.json 에서 설정한 typeRoots 설정이 tsc를 통한 실행은 동작하지만, ts-node 에서 동작하지 않았다. TS2339: Property 'user' does not exist on type 'Request' · Issue #46861 · DefinitelyType When trying to extend the Request interface from the package express to add some custom properties, I'm getting the following typescript error on my routers: ..\node_modules\ts-node\src\index.t... github.com 위 글을 보고 오류를 .. 2021. 12. 17.