Typescript Custom Decorator
·
개발
데코레이터란 (Decorator)? class, method, accessor, property, parameter에 사용할 수 있는 선언의 한 종류이다. `@Decorator` 형식으로 사용을 할 수 있다. 이는 런타임에 호출되는 함수이다. 데코레이터 합성 데코레이터를 사용하다보면 호출 순서에 대해 혼란스러운 순간이 있다. 데코레이터는 내부 요소부터 외부 요소로 향하는 순서로 적용된다. 예를 들어 메서드의 매개변수에 대한 데코레이터가 적용된 후 메서드 자체 그리고 마지막에 클래스 전체에 대한 데코레이터가 적용된다. 같은 종류의 데코레이터의 경우도 유사하다. 수학의 합성함수와 동일하게 작동한다. @f @g x 다음과 같이 데코레이터가 선언되어 있다면 f(g(x))와 동일하게 실행된다. Typescript..
Generic Programming and Type Parameter
·
개발
What is Generic Programming? - Generic programming is a style of computer programming in which algorithms are written in terms of types to-be-specified-later that are then instantiated when needed for specific types provides as parameter. Type parameter? - Type parameter like 'T' in TypeScript, are a fundamental aspect of generic programming, a programming style where algorithms are written in t..
Typescript Type narrowing
·
개발
Typescript's type narrowing - TypeScript has a feature called "type narrowing" which allows the type system to refine the type of variable based on certain checks. For example, if you check whether a variable is not null, TypeScript understands in the subsequent code that this variable is indeed not null. Mutaillity of Obejcts - In JavaScript , obejcts are mutable. THis means that their properti..