typescript 5.0์ด ๋‚˜์™”๋‹ค๊ณ  ํ•˜์—ฌ ๊ฐ„๋‹จํžˆ ์–ด๋–ค ๊ธฐ๋Šฅ๋“ค์ด ์ถ”๊ฐ€๋˜์—ˆ๋Š”์ง€ ์‚ดํŽด๋ณด์•˜๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Typescript 5.0 ๋ฒˆ์—ญ์—์„œ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋‹ค.

๋ฐ์ฝ”๋ ˆ์ดํ„ฐ

๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋Š” ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฐฉ์‹์œผ๋กœ ํด๋ž˜์Šค์™€ ๊ทธ ๋ฉค๋ฒ„๋ฅผ ์‚ฌ์šฉ์ž ์ •์˜ํ•˜๋Š” ECMAScript์˜ ๊ธฐ๋Šฅ์ด๋‹ค. ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋Š” ์ด์ „๋ถ€ํ„ฐ ์ง€์›๋˜์—ˆ์œผ๋‚˜ Typescript 5.0๋ถ€ํ„ฐ๋Š” ๊ณต์‹ ๊ธฐ๋Šฅ์œผ๋กœ ์ง€์›ํ•œ๋‹ค.

function loggedMethod(originalMethod: any, context: ClassMethodDecoratorContext) {
    const methodName = String(context.name);
 
    function replacementMethod(this: any, ...args: any[]) {
        console.log(`LOG: Entering method '${methodName}'.`)
        const result = originalMethod.call(this, ...args);
        console.log(`LOG: Exiting method '${methodName}'.`)
        return result;
    }
 
    return replacementMethod;
}
 
class Person {
    name: string;
    constructor(name: string) {
        this.name = name;
    }
 
    @loggedMethod
    greet() {
        console.log(`Hello, my name is ${this.name}.`);
    }
}
 
const p = new Person("Ron");
p.greet();

const ํƒ€์ž… ํŒŒ๋ผ๋ฏธํ„ฐ

ํŠน์ • ๋ฌธ์ž์—ด๋กœ ํƒ€์ž…์„ ๊ตฌ์„ฑํ•˜๊ณ  ์‹ถ์„ ๋•Œ, ์ฃผ๋กœ as const๋ฅผ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

// The type we wanted:
//    readonly ["Alice", "Bob", "Eve"]
// The type we got:
//    string[]
const names1 = getNamesExactly({ names: ["Alice", "Bob", "Eve"]});
 
// Correctly gets what we wanted:
//    readonly ["Alice", "Bob", "Eve"]
const names2 = getNamesExactly({ names: ["Alice", "Bob", "Eve"]} as const);

ํ•˜์ง€๋งŒ ์ด์ œ๋Š” ์ œ๋„ค๋ฆญ์— const๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ๋น„์Šทํ•œ ํšจ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

type HasNames = { names: readonly string[] };
function getNamesExactly<const T extends HasNames>(arg: T): T["names"] {
//                       ^^^^^
    return arg.names;
}
 
// Inferred type: readonly ["Alice", "Bob", "Eve"]
// Note: Didn't need to write 'as const' here
const names = getNamesExactly({ names: ["Alice", "Bob", "Eve"] });

extends์—์„œ ์—ฌ๋Ÿฌ ํŒŒ์ผ ๊ฐ€์ ธ์˜ค๊ธฐ ๊ฐ€๋Šฅ

typescript 5.0๋ถ€ํ„ฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด tsconfig.json์˜ extends์—์„œ ์—ฌ๋Ÿฌ ํŒŒ์ผ์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ์—ฌ๋Ÿฌ ํŒŒ์ผ์„ ํ™•์žฅํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.

{
    "extends": ["a", "b", "c"],
    "compilerOptions": {
        // ...
    }
}

c๋Š” b๋ฅผ ํ™•์žฅํ•˜๊ณ , b๋Š” a๋ฅผ ํ™•์žฅํ•˜๋Š” ๊ฒƒ๊ณผ ๋น„์Šทํ•œ ํšจ๊ณผ๋ฅผ ๊ฐ€์ง„๋‹ค. ๋”ฐ๋ผ์„œ ์„ค์ •์ด ์ถฉ๋Œ๋˜๋Š” ๊ฒฝ์šฐ ํ›„์ž์˜ ํ•ญ๋ชฉ์ด ์šฐ์„ ๋œ๋‹ค.


๋ชจ๋“  enum์€ ์œ ๋‹ˆ์˜จ enum์ด๋‹ค.

typescript 2.0์—์„œ enum literal type์ด ๋„์ž…๋˜๋ฉด์„œ enum์€ ์ข€ ๋” ํŠน๋ณ„ํ•ด์กŒ๋‹ค. enum literal type์€ ๊ฐ enum ๋ฉค๋ฒ„์— ๊ณ ์œ ํ•œ ํƒ€์ž…์„ ๋ถ€์—ฌํ•˜๊ณ  enum ์ž์ฒด๋ฅผ ๊ฐ ๋ฉค๋ฒ„ํƒ€์ž…์˜ union์œผ๋กœ ๋งŒ๋“ค์—ˆ๋‹ค.

// Color is like a union of Red | Orange | Yellow | Green | Blue | Violet
enum Color {
    Red, Orange, Yellow, Green, Blue, /* Indigo */, Violet
}
 
// Each enum member has its own type that we can refer to!
type PrimaryColor = Color.Red | Color.Green | Color.Blue;
 
function isPrimaryColor(c: Color): c is PrimaryColor {
    // Narrowing literal types can catch bugs.
    // TypeScript will error here because
    // we'll end up comparing 'Color.Red' to 'Color.Green'.
    // We meant to use ||, but accidentally wrote &&.
    return c === Color.Red && c === Color.Green && c === Color.Blue;
}

์ด๋•Œ ๋ฌธ์ œ๋Š” ๋ฉค๋ฒ„ ํƒ€์ž…์ด ์‹ค์ œ ๊ฐ’๊ณผ ์ผ๋ถ€ ์—ฐ๊ด€๋˜์–ด์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ๊ทธ๋ž˜์„œ ๋ฉค๋ฒ„๊ฐ€ ํ•จ์ˆ˜ ํ˜ธ์ถœ๋กœ ์ดˆ๊ธฐํ™”๋˜๋ฉด ๊ฐ’์„ ๊ณ„์‚ฐํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.

enum E {
    Blah = Math.random()
}

Typescript 5.0 ์€ ๊ณ„์‚ฐ๋œ ๊ฐ ๋ฉค๋ฒ„์— ๋Œ€ํ•ด ๊ณ ์œ ํ•œ ํƒ€์ž…์„ ์ƒ์„ฑํ•˜์—ฌ ๋ชจ๋“  enum์„ ๊ณต์šฉ์ฒด enum์œผ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

// typescript 5.0
const a : E.Blah = 10;		// ๋ฌธ์ œ ์—†์Œ
// typescript 5.0 ๋ฏธ๋งŒ
const a : E.Blah = 10; 		// Enum type 'E' has members with initializers that are not literals.

โ€”moduleResolution bundler

typesciprt 4.7์—๋Š” --module, --moduleResolution์— node16, nodenext ์˜ต์…˜์„ ๋„์ž…ํ•˜์—ฌ ECMAScript ๋ชจ๋“ˆ์— ๋Œ€ํ•œ ์ •ํ™•ํ•œ ์กฐํšŒ ๊ทœ์น™์„ ๋ชจ๋ธ๋งํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด๋Š” ๋ช‡๋ช‡ ๊ฐœ๋ฐœ์ž์—๊ฒ ๋ฒˆ๊ฑฐ๋กœ์šด ์„ค์ •์ด์—ˆ๋‹ค.

5.0์—์„œ๋Š” compilerOptionsdp moduleResolution์— bundler ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ฒˆ๋“ค๋Ÿฌ์˜ ๋™์ž‘์„ ๋ชจ๋ธ๋งํ•  ์ˆ˜ ์žˆ๋‹ค.

{
    "compilerOptions": {
        "target": "esnext",
        "moduleResolution": "bundler"
    }
}

ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ์กฐํšŒ ์ „๋žต์„ ๊ตฌํ˜„ํ•˜๋Š” Vite, esbuild, swc, Webpack, Parcel ๋“ฑ์˜ ์ตœ์‹  ๋ฒˆ๋“ค๋Ÿฌ๋ฅผ ์‚ฌ์šฉ ์ค‘์ด๋ผ๋ฉด ์ƒˆ๋กœ์šด bundler์˜ต์…˜์ด ์ ํ•ฉํ•  ๊ฒƒ์ด๋‹ค. ํ•˜์ง€๋งŒ, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ œ์ž‘์ž์ผ ๊ฒฝ์šฐ bundler ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด, ๋ฒˆ๋“ค๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธธ ์ˆ˜ ์žˆ์œผ๋‹ˆ node16, nodenext ์˜ต์…˜์„ ์ถ”์ฒœํ•œ๋‹ค.


Resolution ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ํ”Œ๋ž˜๊ทธ

  • allowImportingTsExtensions : .ts, .mts, .tsx์™€ ๊ฐ™์ด Typescript ์ „์šฉ ํ™•์žฅ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„œ๋กœ๋ฅผ import ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • resolvePackageJsonExports : typescript๊ฐ€ node_modules์˜ ํŒจํ‚ค์ง€๋ฅผ ์ฝ์„ ๊ฒฝ์šฐ, package.json์˜ exports ํ•„๋“œ๋ฅผ ์ฐธ์กฐํ•˜๋„๋ก ํ•œ๋‹ค.
  • resolvePackageJsonImports : package.json์„ ํฌํ•จํ•˜๋Š” ์กฐ์ƒ ๋””๋ ‰ํ„ฐ๋ฆฌ์˜ ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ #์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ์กฐํšŒ๋ฅผ ์ˆ˜ํ–‰ํ•  ๋•Œ, typescript๊ฐ€ package.json์˜ import ํ”Œ๋“œ๋ฅผ ์ฐธ์กฐํ•˜๋„๋ก ๊ฐ•์ œํ•จ
  • allowArbitraryExtensions
    • typescript 5.0์—์„œ import ๊ฒฝ๋กœ๊ฐ€ js๋˜๋Š” ts ํŒŒ์ผ ํ™•์žฅ์ž๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ {ํŒŒ์ผ ๊ธฐ๋ณธ ์ด๋ฆ„}.d.{ํ™•์žฅ์ž}.ts ํ˜•์‹์˜ ํ•ด๋‹น ๊ฒฝ๋กœ์—์„œ ํƒ€์ž…์„ ์ฐพ๋Š”๋‹ค.
    • Typescript์—์„œ๋Š” ์ด ํŒŒ์ผ ํ˜•์‹์„ ์ดํ•ดํ•˜์ง€ ๋ชปํ•˜์—ฌ ๋Ÿฐํƒ€์ž„์—์„œ import๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Œ์„ ์•Œ๋ฆฌ๋Š” ์˜ค๋ฅ˜๋ฅผ ๋‚ด์ง€๋งŒ, ์ด ํ”Œ๋ž˜๊ทธ๋ฅผ ํ†ตํ•ด ์–ต์ œ ํ•  ์ˆ˜ ์žˆ๋‹ค.

customConditions

package.json์˜ exports, imports ํ•„๋“œ๋ฅผ Typescript๊ฐ€ ๋ฆฌ์กธ๋ธŒํ•  ๋•Œ ์„ฑ๊ณตํ•ด์•ผํ•˜๋Š” ์ถ”๊ฐ€ ์กฐ๊ฑด์˜ ๋ชฉ๋ก์„ ๋ฐ›๋Š”๋‹ค. ํ˜„์กดํ•˜๋Š” ์กฐ๊ฑด์— ์ถ”๊ฐ€๋œ๋‹ค.

{
    "compilerOptions": {
        "target": "es2022",
        "moduleResolution": "bundler",
        "customConditions": ["my-condition"]
    }
}
{
    // ...
    "exports": {
        ".": {
            "my-condition": "./foo.mjs",
            "node": "./bar.mjs",
            "import": "./baz.mjs",
            "require": "./biz.mjs"
        }
    }
}

์œ„์™€ ๊ฐ™์€ ๊ฒฝ์šฐ exports, imports ํ•„๋“œ๋ฅผ ๋ฆฌ์กธ๋ธŒํ•  ๋•Œ ํ•ญ์ƒ my-condition์„ ๊ณ ๋ คํ•œ๋‹ค.


โ€”verbatimModuleSyntax

๊ธฐ๋ณธ์ ์œผ๋กœ Typescript๋Š” import elision์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด import๋ฅผ type์„ ๊ฐ€์ ธ์˜ค๊ธฐ๋งŒ์„ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, ์ด๋ฅผ ์ง€์šด๋‹ค.

import { Car } from "./car";
 
export function drive(car: Car) {
    // ...
}
// import ๋ฌธ์„ ์ง€์›€
export function drive(car) {
    // ...
}

type์€ ๊ฐ’์ด ์•„๋‹ˆ๊ธฐ์— ์ง€์šฐ์ง€ ์•Š์œผ๋ฉด ๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ๊ฐ€ ๋‚  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ํ•˜์ง€๋งŒ ๋ช‡๊ฐ€์ง€ ์—ฃ์ง€ ์ผ€์ด์Šค๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด ๋ณ€ํ™˜๋œ ์ฝ”๋“œ๋Š” import ".car"์กฐ์ฐจ ๋‚จ๊ธฐ์ง€ ์•Š๋Š”๋ฐ, ์ด๋Š” ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ๋ฅผ ์ผ์œผํ‚ฌ ์ˆ˜๋„ ์žˆ๋‹ค.

๋”ฐ๋ผ์„œ Typescript์—์„œ๋Š” type ์ˆ˜์ •์ž๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ํ•˜๋Š” --importsNotUsedAsValues, ์ผ๋ถ€ ๋ชจ๋“ˆ ์—˜๋ฆฌ์…˜ ๋™์ž‘์„ ๋ฐฉ์ง€ํ•˜๋Š” --perserveValueImports, Typescript๊ฐ€ ์—ฌ๋Ÿฌ ์ปดํŒŒ์ผ๋Ÿฌ์—์„œ ์ž‘๋™ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๋Š” --isolatedModules ํ”Œ๋ž˜๊ทธ๊ฐ€ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด ํ”Œ๋ž˜๊ทธ๋“ค์€ ์ดํ•ดํ•˜๊ธฐ ์–ด๋ ต๊ณ , ์—์ง€ ์ผ€์ด์Šค ์—ญ์‹œ ์กด์žฌํ•œ๋‹ค.

Typescript 5.0์—์„œ๋Š” --verbatimModuleSyntax ๋ฅผ ์ ์šฉํ•˜์—ฌ type ์ˆ˜์ •์ž๊ฐ€ ์—†๋Š” ๋ชจ๋“  import, export๋Š” ๊ทธ๋Œ€๋กœ ์œ ์ง€ํ•˜๋„๋ก ํ–ˆ๋‹ค. type ์ˆ˜์ •์ž๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  ํ•ญ๋ชฉ์€ ์™„์ „ํžˆ ์‚ญ์ œ๋œ๋‹ค.

// Erased away entirely.
import type { A } from "a";
 
// Rewritten to 'import { b } from "bcd";'
import { b, type c, type d } from "bcd";
 
// Rewritten to 'import {} from "xyz";'
import { type xyz } from "xyz";

ํ•˜์ง€๋งŒ ์ด ํ”Œ๋ž˜๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ECMAScript import์™€ export๋Š”, ๋‹ค๋ฅธ ๋ชจ๋“ˆ ์‹œ์Šคํ…œ์„ ์•”์‹œํ•˜๋Š” ํŒŒ์ผ ํ™•์žฅ์ž ๋˜๋Š” ์„ธํŒ…์ด ์žˆ์„๋•Œ require ๋กœ ์žฌ์ž‘์„ฑ๋˜์ง€ ์•Š๋Š”๋‹ค. ๋Œ€์‹  ์˜ค๋ฅ˜๋ฅผ ๋‚ธ๋‹ค. ๋งŒ์•ฝ require๋‚˜ module.exports๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ๋ฅผ emit ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ES2015 ์ด์ „์˜ Typescript ๋ชจ๋“ˆ ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค.

Input TypescriptOutput Javascript
import foo = require("foo"); const foo = require("foo");
function foo() {}
function bar() {}
function baz() {}
export = { foo, bar, baz };
function foo() {}
function bar() {}
function baz() {}
module.exports = { foo, bar, baz };

์ด๋Š” ๋ช‡๋ช‡ ์ƒํ™ฉ์—์„œ ๋„์›€์ด ๋˜๋Š”๋ฐ, ์˜ˆ๋ฅผ๋“ค์–ด ๊ฐœ๋ฐœ์ž๊ฐ€ package.json์˜ --module node16์„ ์„ค์ •ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ๊ฐœ๋ฐœ์ž๋Š” ์ธ์ง€ํ•˜์ง€ ๋ชปํ•œ์ฑ„ ES ๋ชจ๋“ˆ ๋Œ€์‹  CommonJS ๋ชจ๋“ˆ์„ ์ž‘์„ฑํ•˜๊ธฐ ์‹œ์ž‘ํ•˜์—ฌ ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ์กฐํšŒ ๊ทœ์น™๊ณผ JavaScript ์ถœ๋ ฅ์„ ์ œ๊ณตํ•˜๊ฒŒ ๋œ๋‹ค. ์ด ํ”Œ๋ž˜๊ทธ๋Š” ๊ตฌ๋ฌธ์ด ์˜๋„์ ์œผ๋กœ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉ์ค‘์ธ ํŒŒ์ผ ํ˜•์‹์— ๋Œ€ํ•ด ์˜๋„์ ์œผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

-verbatimModuleSyntax์€ --importsNotUsedAsValues ๋ฐ --preserveValueImports๋ณด๋‹ค ๋” ์ผ๊ด€๋œ ์Šคํ† ๋ฆฌ๋ฅผ ์ œ๊ณตํ•˜๋ฏ€๋กœ, ๊ธฐ์กด์˜ ๋‘ ํ”Œ๋ž˜๊ทธ๋Š” ์ด ๊ตฌ๋ฌธ์œผ๋กœ ๋Œ€์ฒด๋œ๋‹ค.


Support for export type *

๊ธฐ์กด์—” export * from "module"์ด๋‚˜ export * as ns from "module" ์ฒ˜๋Ÿผ re-export๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ–ˆ๋‹ค. Typescript 5.0 ๋ถ€ํ„ฐ๋Š” ๊ฐ€๋Šฅํ•˜๋‹ค.

// models/vehicles.ts
export class Spaceship {
  // ...
}
 
// models/index.ts
export type * as vehicles from "./vehicles";
 
// main.ts
import { vehicles } from "./models";
 
function takeASpaceship(s: vehicles.Spaceship) {
  // โœ… ok - `vehicles` only used in a type position
}
 
function makeASpaceship() {
  return new vehicles.Spaceship();
  //         ^^^^^^^^
  // 'vehicles' cannot be used as a value because it was exported using 'export type'.
}

@satisfies Support in JSDoc

Typescript 4.9์—์„œ satisfies ์—ฐ์‚ฐ์ž๊ฐ€ ์ถ”๊ฐ€๋๋‹ค. ์ด ์—ฐ์‚ฐ์ž๋Š” ํƒ€์ž…์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๊ณ , ํ‘œํ˜„์‹์ด ํƒ€์ž…์— ํ˜ธํ™˜๋˜๋Š”์ง€๋งŒ ํ™•์ธํ•œ๋‹ค.

interface CompilerOptions {
    strict?: boolean;
    outDir?: string;
    // ...
}
 
interface ConfigSettings {
    compilerOptions?: CompilerOptions;
    extends?: string | string[];
    // ...
}
 
let myConfigSettings = {
    compilerOptions: {
        strict: true,
        outDir: "../lib",
        // ...
    },
 
    extends: [
        "@tsconfig/strictest/tsconfig.json",
        "../../../tsconfig.base.json"
    ],
 
} satisfies ConfigSettings;

์œ„ ์ฝ”๋“œ์—์„œ Typescript๋Š” myConfigSettings.extends๊ฐ€ ๋ฐฐ์—ด์ž„์„ ์•„๋Š”๋ฐ, ์ด๋Š” ConfigSettings์™€ ํ˜ธํ™˜ ๊ฐ€๋Šฅํ•œ์ง€๋งŒ ํ™•์ธํ•˜๊ณ , myConfigSettings์˜ ํƒ€์ž…์„ ๋ณ€๊ฒฝํ•˜์ง€๋Š” ์•Š์•˜๊ธฐ ๋–„๋ฌธ์ด๋‹ค. ๋”ฐ๋ผ์„œ extends์— map ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด๋„ ์˜ค๋ฅ˜๊ฐ€ ๋‚˜์ง€ ์•Š๋Š”๋‹ค.

์ด satisfies๊ฐ€ JSDoc ํƒœ๊ทธ์— ์ถ”๊ฐ€๋˜์—ˆ๋‹ค.

// @ts-check
 
/**
 * @typedef CompilerOptions
 * @prop {boolean} [strict]
 * @prop {string} [outDir]
 */
 
/**
 * @satisfies {CompilerOptions}
 */
let myCompilerOptions = {
    outdir: "../lib",
//  ~~~~~~ oops! we meant outDir
};

๋‹ค์Œ๊ณผ ๊ฐ™์ด /** @satisfies */ ์ธ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, ํ•จ์ˆ˜ ํ˜ธ์ถœ๊ณผ ๊ฐ™์€ ๊ณณ์—์„œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

let myConfigSettings = /** @satisfies {ConfigSettings} */ ({
    compilerOptions: {
        strict: true,
        outDir: "../lib",
    },
    extends: [
        "@tsconfig/strictest/tsconfig.json",
        "../../../tsconfig.base.json"
    ],
});
 
// ํ•จ์ˆ˜ ํ˜ธ์ถœ์—์„œ ์‚ฌ์šฉ
compileCode(/** @satisfies {ConfigSettings} */ ({
    // ...
}));

@overload Support in JSDoc

Typescript์—์„œ๋Š” ํ•จ์ˆ˜ ์˜ค๋ฒ„๋กœ๋“œ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ์ด๋กœ์จ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ œํ•œํ•  ์ˆ˜ ์žˆ๋‹ค.

// Our overloads:
function printValue(str: string): void;
function printValue(num: number, maxFractionDigits?: number): void;
 
// Our implementation:
function printValue(value: string | number, maximumFractionDigits?: number) {
    if (typeof value === "number") {
        const formatter = Intl.NumberFormat("en-US", {
            maximumFractionDigits,
        });
        value = formatter.format(value);
    }
 
    console.log(value);
}

์ด๋Ÿฌํ•œ ์˜ค๋ฒ„๋กœ๋“œ ๊ธฐ๋Šฅ์„ @overload ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด์„œ JSDoc ์•ˆ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

// @ts-check
 
/**
 * @overload
 * @param {string} value
 * @return {void}
 */
 
/**
 * @overload
 * @param {number} value
 * @param {number} [maximumFractionDigits]
 * @return {void}
 */
 
/**
 * @param {string | number} value
 * @param {number} [maximumFractionDigits]
 */
function printValue(value, maximumFractionDigits) {
    if (typeof value === "number") {
        const formatter = Intl.NumberFormat("en-US", {
            maximumFractionDigits,
        });
        value = formatter.format(value);
    }
 
    console.log(value);
}

Passing Emit-Specific Flags Under --build

--build ๋ชจ๋“œ์—์„œ ๋‹ค์Œ ํ”Œ๋ž˜๊ทธ๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ๋‹ค. ๋นŒ๋“œ ์‹œ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•์„ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค.

  • --declaration
  • โ€”-emitDeclarationOnly
  • โ€”-declarationMap
  • โ€”-sourceMap
  • โ€”-inlineSourceMap

Case-Insensitive Import Sorting in Editors

VSCode ์™€ ๊ฐ™์€ ์ฝ”๋“œ์—๋””ํ„ฐ์—์„œ TypeScript๋Š” import, export ๋ชฉ๋ก ์ •๋ ฌ์„ ์ง€์›ํ•œ๋‹ค. ํ•˜์ง€๋งŒ Typescript๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ •๋ ฌํ•œ๋‹ค. ์•„์Šคํ‚ค ๋ฌธ์ž ์ธ์ฝ”๋”ฉ ์ƒ ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž ์•ž์ด๊ธฐ์— ๋‹ค์Œ ์ •๋ ฌ์€ Typescript์—์„œ ์ ์ ˆํ•˜๋‹ค.

import {
    Toggle,
    freeze,
    toBoolean,
} from "./utils";

ํ•˜์ง€๋งŒ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š๊ณ  ์ •๋ ฌํ•˜๊ณ  ์‹ถ์„ ์ˆ˜๋„ ์žˆ๋‹ค. ์ด์ œ๋Š” organizeImports ์˜ต์…˜์ด ์ถ”๊ฐ€๋˜์–ด ํ•ด๋‹น ์„ค์ •์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

{
    "typescript.unstable": {
        // Should sorting be case-sensitive? Can be:
        // - true
        // - false
        // - "auto" (auto-detect)
        "organizeImportsIgnoreCase": "auto",
 
        // Should sorting be "ordinal" and use code points or consider Unicode rules? Can be:
        // - "ordinal"
        // - "unicode"
        "organizeImportsCollation": "ordinal",
 
        // Under `"organizeImportsCollation": "unicode"`,
        // what is the current locale? Can be:
        // - [any other locale code]
        // - "auto" (use the editor's locale)
        "organizeImportsLocale": "en",
 
        // Under `"organizeImportsCollation": "unicode"`,
        // should upper-case letters or lower-case letters come first? Can be:
        // - false (locale-specific)
        // - "upper"
        // - "lower"
        "organizeImportsCaseFirst": false,
 
        // Under `"organizeImportsCollation": "unicode"`,
        // do runs of numbers get compared numerically (i.e. "a1" < "a2" < "a100")? Can be:
        // - true
        // - false
        "organizeImportsNumericCollation": true,
 
        // Under `"organizeImportsCollation": "unicode"`,
        // do letters with accent marks/diacritics get sorted distinctly
        // from their "base" letter (i.e. is รฉ different from e)? Can be
        // - true
        // - false
        "organizeImportsAccentCollation": true
    },
    "javascript.unstable": {
        // same options valid here...
    },
}

Exhaustive switch/case Completions

switch ๋ฌธ์„ ์ž‘์„ฑํ•  ๋•Œ ๊ฒ€์‚ฌ ๋Œ€์ƒ์— ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž…์ด ์žˆ๋Š”์ง€ ๊ฐ์ง€ํ•œ๋‹ค. ๊ฐ์ง€๋˜๋ฉด ๋ฐœ๊ฒฌ๋œ์ง€ ์•Š์€ ๊ฐ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ์Šค์นดํด๋”ฉํ•˜๋Š” ์™„๊ฒฐ์„ฑ์„ ์ œ๊ณตํ•œ๋‹ค.

type Fruit = 
	| { kind : "apple" }
	| { kind : "orange" }
	| { kind : "banana" }
 
function nom(fruit: Fruit) {
	switch(fruit.kind) {
    case 						// case ๋ฌธ์„ ์ž‘์„ฑํ•˜๋ฉด ์ž๋™ ์™„์„ฑ์œผ๋กœ case "apple": case "orange": case "banana"๊ฐ€ ์ƒ๊น€
  }
}

Speed, Memory, and Package Size Optimizations

Typescript 5.0์—์„œ๋Š” ์ฝ”๋“œ ๊ตฌ์กฐ, ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ, ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฌํ˜„์„ ๋ณ€๊ฒฝํ•˜์—ฌ ์ „์ฒด ๊ฒฝํ—˜์„ ์ข€ ๋” ๋น ๋ฅด๊ฒŒ ๋งŒ๋“ค์—ˆ๋‹ค.

image

img


Breaking Changes and Deprecations

Runtime Requirements

Typescript 5.0๋ถ€ํ„ฐ๋Š” ECMAScript 2018์„ ๋Œ€์ƒ์œผ๋กœ ํ•œ๋‹ค. ๋˜ํ•œ, Typescipt ํŒจํ‚ค์ง€๋Š” ์ตœ์†Œ ์š”๊ตฌ ์—”์ง„์„ 12.20์œผ๋กœ ์„ค์ •ํ–ˆ๋‹ค.

lib.d.ts Changes

DOM ์œ ํ˜•์ด ์ƒ์„ฑ๋˜๋Š” ๋ฐฉ์‹์ด ๋ณ€๊ฒฝ๋˜์–ด ๊ธฐ์กด ์ฝ”๋“œ์— ์˜ํ–ฅ์„ ๋ฏธ์น  ์ˆ˜ ์žˆ๋‹ค. ํŠนํžˆ ํŠน์ • property๊ฐ€ ์ˆซ์ž์—์„œ ์ˆซ์ž ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜๋˜์—ˆ๋‹ค. ์ž˜๋ผ๋‚ด๊ธฐ, ๋ณต์‚ฌ, ๋ถ™์—ฌ๋„ฃ๊ธฐ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ํ”„๋กœํผํ‹ฐ์™€ ๋ฉ”์„œ๋“œ๊ฐ€ ์ธํ„ฐํŽ˜์ด์Šค ์ „๋ฐ˜์œผ๋กœ ์ด๋™๋˜์—ˆ๋‹ค.

API Breaking Changes

๋ชจ๋“ˆ๋กœ ์ „ํ™˜ํ•˜๊ณ , ๋ถˆํ•„์š”ํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ฑฐํ–ˆ์œผ๋ฉฐ ์ผ๋ถ€ ์ •ํ™•์„ฑ์„ ๊ฐœ์„ ํ–ˆ๋‹ค.

Forbidden Implicit Coercions in Relational Operators

Typescript์˜ ํŠน์ • ์—ฐ์‚ฐ์€ ์•”์‹œ์ ์œผ๋กœ ๋ฌธ์ž์—ด์„ ์ˆซ์ž๋กœ ๊ฐ•์ œ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๊ฒฝ์šฐ ๊ฒฝ๊ณ ํ•˜๊ณ  ์žˆ๋‹ค.

function func(ns: number | string) {
  return ns * 4; // Error, possible implicit coercion
}

5.0 ๋ถ€ํ„ฐ๋Š” ๊ด€๊ณ„ ์—ฐ์‚ฐ์ž >, <, โ‡, >= ์—๋„ ์ด ๊ธฐ๋Šฅ์ด ์ ์šฉ๋œ๋‹ค. ์›ํ•˜๋Š” ๊ฒฝ์šฐ +๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”ผ์—ฐ์‚ฐ์ž๋ฅผ ์ˆซ์ž๋กœ ๋ช…์‹œ์ ์œผ๋กœ ๊ฐ•์ œํ•  ์ˆ˜ ์žˆ๋‹ค.

function func(ns: number | string) {
  return ns > 4; // Now also an error
}
 
function func(ns: number | string) {
  return +ns > 4; // OK
}

Enum Overhaul

Enum์„ ์‚ฌ์šฉํ•  ๋•Œ Enum ์œ ํ˜•์— ๋„๋ฉ”์ธ ์™ธ๋ถ€ ๋ฆฌํ„ฐ๋Ÿด์„ ํ• ๋‹นํ•˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋„๋ก ์ถ”๊ฐ€๋๋‹ค.

enum SomeEvenDigit {
    Zero = 0,
    Two = 2,
    Four = 4
}
 
// Now correctly an error
let m: SomeEvenDigit = 1;

๋˜ ์ˆซ์ž์™€ ๊ฐ„์ ‘ string enum ์ฐธ์กฐ๊ฐ€ ํ˜ผํ•ฉ๋˜์–ด ์„ ์–ธ๋œ ๊ฐ’์ด ์žˆ๋Š” enum์—์„œ ์˜ค๋ฅ˜๋ฅผ ์ œ๋Œ€๋กœ ์ƒ์„ฑํ•˜๋„๋ก ๋ณ€๊ฒฝ๋๋‹ค.

enum Letters {
    A = "a"
}
enum Numbers {
    one = 1,
    two = Letters.A
}
 
// Now correctly an error
const t: number = Numbers.two;

More Accurate Type-Checking for Parameter Decorators in Constructors Under --experimentalDecorators

decorator์— ๋Œ€ํ•œ ์ข€ ๋” ์ •ํ™•ํ•œ type-checking์ด ๋˜๋„๋ก ํ•˜๋Š” ์˜ต์…˜์ด ์ถ”๊ฐ€๋˜์—ˆ๋‹ค. ํŠนํžˆ ์ƒ์„ฑ์ž ํŒŒ๋ผ๋ฏธํ„ฐ์—์„œ ์‚ฌ์šฉํ•  ๋•Œ ํšจ๊ณผ์ ์ด๋‹ค.

export declare const inject:
  (entity: any) =>
    (target: object, key: string | symbol, index?: number) => void;
 
export class Foo {}
 
export class C {
    constructor(@inject(Foo) private x: any) {
    }
}

key๊ฐ€ string | symbol์„ ์˜ˆ์ƒํ•˜๊ธฐ์— ์ด ํ˜ธ์ถœ์€ ์‹คํŒจํ•˜์ง€๋งŒ ์ƒ์„ฑ์ž ํŒŒ๋ผ๋ฏธํ„ฐ๋Š” undefinedํ‚ค๋ฅผ ๋ฐ›๋Š”๋‹ค. ์˜ฌ๋ฐ”๋ฅธ ์ˆ˜์ •์€ inject์˜ key์˜ ํƒ€์ž…์„ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ๋งŒ์•ฝ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉ์ค‘์ธ ๊ฒฝ์šฐ์—๋Š” inject๋ฅผ ์ข€ ๋” type-safeํ•œ decorator๋กœ ๊ฐ์‹ธ๊ณ  key์— type assertion์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

Deprecations and Default Changes

์ด์ œ ๋‹ค์Œ ์„ค์ •๊ฐ’๋“ค์€ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.

  • --target: ES3
  • --out
  • --noImplicitUseStrict
  • --keyofStringsOnly
  • --suppressExcessPropertyErrors
  • --suppressImplicitAnyIndexErrors
  • --noStrictGenericChecks
  • --charset
  • --importsNotUsedAsValues
  • --preserveValueImports
  • prepend in project references

Typescript 5.5๊นŒ์ง€๋Š” ํ—ˆ์šฉํ•˜์ง€๋งŒ ์ดํ›„๋กœ๋Š” ๊ฒฝ๊ณ ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. ๋‹จ, "ignoreDeperecations": "5.0"์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ฒฝ๊ณ ๋ฅผ ์—†์•จ ์ˆ˜ ์žˆ๋‹ค.

ํ”„๋กœ์ ํŠธ ๋‚ด์—์„œ ๋™์ผํ•œ ํŒŒ์ผ ์ด๋ฆ„์„ ์ฐธ์กฐํ•˜๋Š” ๋ชจ๋“  ์ฐธ์กฐ๊ฐ€ ์ผ€์ด์Šค์— ๋Œ€ํ•ด ๋™์˜ํ•˜๋„๋ก ๋ณด์žฅํ•˜๋Š” --forceConsistentCasingInFileNames๋Š” ์ด์ œ true๋กœ ๊ธฐ๋ณธ ์„ค์ •๋œ๋‹ค.


์ถœ์ฒ˜

https://velog.io/@hustle-dev/TypeScript-5.0-%EB%B2%88%EC%97%AD#%EB%8D%B0%EC%BD%94%EB%A0%88%EC%9D%B4%ED%84%B0

https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#moduleresolution-bundler