Frontend2024년 4월 22일2분 읽기

TypeScript 5.0 새 기능 — Decorators, const Type Parameters

YS
YoungSam
조회 417

TC39 Decorators 정식 지원

TypeScript 5.0부터 TC39 Stage 3 Decorators가 정식 지원됩니다. 기존 experimental decorators와 문법이 다릅니다.

function logged(target: any, context: ClassMethodDecoratorContext) {
  return function (...args: any[]) {
    console.log(`Calling ${String(context.name)}`);
    return target.apply(this, args);
  };
}

class MyClass {
  @logged
  greet() { return "hello"; }
}

const Type Parameters

function createTuple(...args: T): T {
  return args;
}
const tuple = createTuple(1, "hello", true);
// type: readonly [1, "hello", true]
TypeScriptJavaScript

댓글 0

아직 댓글이 없습니다.