강의

멘토링

로드맵

BEST
Programming

/

Programming Language

[Renewal] TypeScript All-in-One: Part 1. Basic Syntax

Learn the basic syntax of TypeScript, and explore how to analyze types written by others as well as how to write your own types.

(4.9) 67 reviews

1,586 learners

Level Basic

Course period Unlimited

  • zerocho
TypeScript
TypeScript
TypeScript
TypeScript
zerocho님의 프로필 이미지

Edited

TypeScript 5.1 Released Bind Function Changes

bind < T >( this : T , thisArg: ThisParameterType< T >): OmitThisParameter< T > ;

bind < T , A extends any [] , B extends any [] , R >( this : ( this : T , ...args: [... A , ... B ]) => R , thisArg: T , ...args: A ): (...args: B ) => R ;

 

The bind function has been simplified. [...A, ...B] might be confusing. Think of A as arguments to be bound to the original function, and B as arguments not to be bound. In other words, if the original function had both A and B as parameters, the newly bound function only needs B.

const sum = (a1, a2, b1, b2) => a1 + a2 + b1 + b2;
const sum1 = sum.bind(null, 1, 2); // a1에 1, a2에 2를 bind
sum1(3, 4); // 1 + 2 + 3 + 4 === 3, a1, a2는 이미 bind되었으므로 남은 b1, b2만 제공

Previously it was like this:

bind < T , A0 , A extends any [] , R >( this : ( this : T , arg0: A0 , ...args: A ) => R , thisArg: T , arg0: A0 ): (... args: A ) => R ;
bind < T , A0 , A1 , A extends any [] , R >( this : ( this : T , arg0: A0 , arg1: A1 , ...args: A ) => R , thisArg: T , arg0: A0 , arg1: A1 ): (...args: A ) => R ;
bind < T , A0 , A1 , A2 , A extends any [] , R >( this : ( this : T , arg0 : A0 , arg1: A1 , arg2: A2 , ...args: A ) => R , thisArg : T , arg0: A0 , arg1: A1 , arg2: A2 ): (...args: A ) => R ;
bind < T , A0 , A1 , A2 , A3 , A extends any [] , R >( this : ( this : T , arg0: A0 , arg1: A1 , arg2: A2 , arg3: A3 , ...args: A ) => R , thisArg: T , arg0: A0 , arg1: A1 , arg2: A2 , arg3: A3 ): (...args: A ) => R ;
bind < T , AX , R >( this : ( this : T , ...args: AX []) => R , thisArg: T , ...args: AX []): (...args: AX []) => R ;

Comment