문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판다음 판 | 이전 판 | ||
| typescript:deep:type [2019/11/19 12:23] – [Solution 2 - Function] taekgu | typescript:deep:type [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 12: | 줄 12: | ||
| OK, this is the most ugly way to achieve it, you can simply declare a variable as '' | OK, this is the most ugly way to achieve it, you can simply declare a variable as '' | ||
| - | 좋아, 이것은 가장 못난 접근 방법이다, | + | 좋아, 이것은 가장 못난 접근 방법이다, |
| < | < | ||
| 줄 25: | 줄 25: | ||
| Sometimes, when you design the interfaces, you have no idea what the actual signature will be, but instead declaring a ' | Sometimes, when you design the interfaces, you have no idea what the actual signature will be, but instead declaring a ' | ||
| + | |||
| + | 때로는 인터페이스를 디자인 할 때 실제 서명이 무엇인지 모르지만 ' | ||
| < | < | ||
| 줄 35: | 줄 37: | ||
| OK. So now when you want assign a value other than function to this variable ' | OK. So now when you want assign a value other than function to this variable ' | ||
| + | 좋아. 이제 변수 ' | ||
| > Type ' | > Type ' | ||
| ==== Solution 3 - More specific signature: ==== | ==== Solution 3 - More specific signature: ==== | ||
| + | |||
| + | Now, as your projets goes on, you have whole idea of what's going on there. So you can go back and modify your declaration to a more precise version using the fancy arrow function syntax, feel free to use it, it maked as ' | ||
| + | |||
| + | 이제, 당신의 프로젝트가 진행됨에 따라, 당신은 거기에 대한 전체를 알고 있다. 그래서 당신은 뒤로 돌아가 당신의 선언를 연습버젼에서 화려한 화살표 함수문법으로 수정할 수 있다. 화살표함수는 ECMA2015에서 표준이 되었다. | ||
| + | < | ||
| + | let a: (para: string) => string; | ||
| + | a = function(pass: | ||
| + | return pass; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The syntax here is very simple, it is just like the lambda function in Java or C#, the ' | ||
| + | |||
| + | 여기 문법은 매우 단순하고, | ||
| + | ==== Solution 4 - Use type ==== | ||
| + | |||
| + | We can use '' | ||
| + | |||
| + | '' | ||
| + | |||
| + | < | ||
| + | type read = (name: string) => void; | ||
| + | const test: read = (value: string) => { | ||
| + | console.log(value); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Solution 5 - Interface them all ==== | ||
| + | |||
| + | We are Typescript, we'd love to use the beloved '' | ||
| + | 우리는 타입스크립트에서는, | ||
| + | < | ||
| + | interface read { | ||
| + | (name: string): string; | ||
| + | } | ||
| + | |||
| + | const test: read = (value: string) => value; | ||
| + | </ | ||
| + | |||
| + | ==== Summary ==== | ||
| + | |||
| + | In pratice, I often use '' | ||
| + | |||
| + | 경험적으로 나는 4번 Type을 선호한다. 아마도 '' | ||