{"id":225,"date":"2026-08-03T09:51:44","date_gmt":"2026-08-03T01:51:44","guid":{"rendered":"https:\/\/yykcj.com\/?p=225"},"modified":"2026-08-03T09:51:44","modified_gmt":"2026-08-03T01:51:44","slug":"typescript-5-x-%e8%bf%9b%e9%98%b6%e7%94%a8%e6%b3%95%ef%bc%9a%e4%bb%8e%e7%b1%bb%e5%9e%8b%e4%bd%93%e6%93%8d%e5%88%b0%e8%a3%85%e9%a5%b0%e5%99%a8%ef%bc%8c%e6%8f%90%e5%8d%87%e4%bb%a3%e7%a0%81%e8%b4%a8","status":"publish","type":"post","link":"https:\/\/yykcj.com\/?p=225","title":{"rendered":"TypeScript 5.x \u8fdb\u9636\u7528\u6cd5\uff1a\u4ece\u7c7b\u578b\u4f53\u64cd\u5230\u88c5\u9970\u5668\uff0c\u63d0\u5347\u4ee3\u7801\u8d28\u91cf\u4e0e\u5f00\u53d1\u6548\u7387"},"content":{"rendered":"<h2>\u5f15\u8a00<\/h2>\n<p>TypeScript 5.x \u5df2\u7ecf\u53d1\u5e03\u4e86\u4e00\u6bb5\u65f6\u95f4\uff0c\u5e26\u6765\u4e86\u8bb8\u591a\u4ee4\u4eba\u5174\u594b\u7684\u65b0\u7279\u6027\u3002\u7136\u800c\uff0c\u5f88\u591a\u5f00\u53d1\u8005\u4ecd\u7136\u505c\u7559\u5728\u57fa\u7840\u7684\u7c7b\u578b\u6ce8\u89e3\u4e0a\uff0c\u6ca1\u6709\u5145\u5206\u5229\u7528\u8fd9\u4e9b\u5f3a\u5927\u7684\u529f\u80fd\u3002\u672c\u6587\u5c06\u5e26\u4f60\u6df1\u5165 TypeScript 5.x \u7684\u8fdb\u9636\u7528\u6cd5\uff0c\u5305\u62ec const \u7c7b\u578b\u53c2\u6570\u3001\u6a21\u677f\u5b57\u9762\u91cf\u7c7b\u578b\u3001\u88c5\u9970\u5668\u65b0\u6807\u51c6\u7b49\uff0c\u5e76\u901a\u8fc7\u5b9e\u9645\u6848\u4f8b\u5c55\u793a\u5982\u4f55\u5e94\u7528\u5b83\u4eec\u89e3\u51b3\u771f\u5b9e\u95ee\u9898\u3002<\/p>\n<p>\u65e0\u8bba\u4f60\u662f\u60f3\u63d0\u5347\u4ee3\u7801\u7684\u7c7b\u578b\u5b89\u5168\u6027\uff0c\u8fd8\u662f\u60f3\u8ba9\u4ee3\u7801\u66f4\u52a0\u7075\u6d3b\uff0c\u672c\u6587\u90fd\u5c06\u4e3a\u4f60\u63d0\u4f9b\u5b9e\u7528\u7684\u6280\u5de7\u548c\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<h2>1. const \u7c7b\u578b\u53c2\u6570\uff1a\u8ba9\u6cdb\u578b\u66f4\u7cbe\u786e<\/h2>\n<p>\u5728 TypeScript 5.0 \u4e2d\uff0c\u65b0\u589e\u4e86 <code>const<\/code> \u7c7b\u578b\u53c2\u6570\uff0c\u5141\u8bb8\u6211\u4eec\u5728\u6cdb\u578b\u4e2d\u58f0\u660e\u7c7b\u578b\u53c2\u6570\u4e3a <code>const<\/code>\uff0c\u4ece\u800c\u4fdd\u7559\u5b57\u9762\u91cf\u7c7b\u578b\u7684\u7cbe\u786e\u6027\u3002<\/p>\n<h3>\u95ee\u9898\u573a\u666f<\/h3>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u4ece\u5bf9\u8c61\u4e2d\u63d0\u53d6\u67d0\u4e2a\u5c5e\u6027\u7684\u503c\uff1a<\/p>\n<pre><code class=\"language-typescript\">\nfunction getValue&lt;T, K extends keyof T&gt;(obj: T, key: K): T[K] {\n    return obj[key];\n}\n\nconst obj = { name: &#x27;Alice&#x27;, age: 30 };\nconst name = getValue(obj, &#x27;name&#x27;); \/\/ string\n<\/code><\/pre>\n<p>\u8fd9\u91cc <code>name<\/code> \u7684\u7c7b\u578b\u662f <code>string<\/code>\uff0c\u800c\u4e0d\u662f\u5b57\u9762\u91cf\u7c7b\u578b <code>'Alice'<\/code>\uff0c\u56e0\u4e3a\u6211\u4eec\u4e22\u5931\u4e86\u5177\u4f53\u7684\u5b57\u9762\u91cf\u4fe1\u606f\u3002<\/p>\n<h3>\u4f7f\u7528 const \u7c7b\u578b\u53c2\u6570<\/h3>\n<p>\u5728 TypeScript 5.0 \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/p>\n<pre><code class=\"language-typescript\">\nfunction getValue&lt;const T, K extends keyof T&gt;(obj: T, key: K): T[K] {\n    return obj[key];\n}\n\nconst obj = { name: &#x27;Alice&#x27;, age: 30 };\nconst name = getValue(obj, &#x27;name&#x27;); \/\/ &#x27;Alice&#x27; \u5b57\u9762\u91cf\u7c7b\u578b\n<\/code><\/pre>\n<p>\u901a\u8fc7\u5728 <code>T<\/code> \u524d\u52a0\u4e0a <code>const<\/code>\uff0cTypeScript \u4f1a\u63a8\u65ad\u51fa <code>obj<\/code> \u7684\u7c7b\u578b\u4e3a <code>{ readonly name: 'Alice', readonly age: 30 }<\/code>\uff0c\u56e0\u6b64 <code>name<\/code> \u7684\u7c7b\u578b\u5c31\u662f <code>'Alice'<\/code>\u3002<\/p>\n<h3>\u7ed3\u5408\u6570\u7ec4\u7684 const \u53c2\u6570<\/h3>\n<p><code>const<\/code> \u7c7b\u578b\u53c2\u6570\u4e5f\u9002\u7528\u4e8e\u6570\u7ec4\uff0c\u53ef\u4ee5\u63a8\u65ad\u51fa\u5143\u7ec4\u7c7b\u578b\uff1a<\/p>\n<pre><code class=\"language-typescript\">\nfunction tuple&lt;const T extends any[]&gt;(...args: T): T {\n    return args;\n}\n\nconst t = tuple(&#x27;hello&#x27;, 42, true); \/\/ readonly [&#x27;hello&#x27;, 42, true]\n<\/code><\/pre>\n<p><strong>\ud83d\udca1 \u63d0\u793a<\/strong>\uff1a<code>const<\/code> \u7c7b\u578b\u53c2\u6570\u5728\u9700\u8981\u7cbe\u786e\u7c7b\u578b\u63a8\u65ad\u7684\u573a\u666f\u975e\u5e38\u6709\u7528\uff0c\u6bd4\u5982\u5904\u7406\u914d\u7f6e\u5bf9\u8c61\u6216\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u65f6\u3002<\/p>\n<h2>2. \u6a21\u677f\u5b57\u9762\u91cf\u7c7b\u578b\uff1a\u6784\u5efa\u5f3a\u5927\u7684\u5b57\u7b26\u4e32\u7c7b\u578b<\/h2>\n<p>\u6a21\u677f\u5b57\u9762\u91cf\u7c7b\u578b\u5728 TypeScript 4.1 \u4e2d\u5f15\u5165\uff0c\u4f46\u5728 5.x \u4e2d\u5f97\u5230\u4e86\u8fdb\u4e00\u6b65\u6269\u5c55\u3002\u5b83\u4eec\u5141\u8bb8\u6211\u4eec\u57fa\u4e8e\u5b57\u7b26\u4e32\u6a21\u677f\u521b\u5efa\u590d\u6742\u7684\u7c7b\u578b\u3002<\/p>\n<h3>\u57fa\u7840\u7528\u6cd5<\/h3>\n<pre><code class=\"language-typescript\">\ntype EventName = `on${Capitalize&lt;string&gt;}`;\n\nconst handleClick: EventName = &#x27;onClick&#x27;; \/\/ \u6b63\u786e\nconst handleChange: EventName = &#x27;onChange&#x27;; \/\/ \u6b63\u786e\nconst invalid: EventName = &#x27;click&#x27;; \/\/ \u9519\u8bef\n<\/code><\/pre>\n<h3>\u5b9e\u9645\u6848\u4f8b\uff1a\u7c7b\u578b\u5b89\u5168\u7684\u4e8b\u4ef6\u7cfb\u7edf<\/h3>\n<p>\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u6a21\u677f\u5b57\u9762\u91cf\u7c7b\u578b\u6784\u5efa\u4e00\u4e2a\u7c7b\u578b\u5b89\u5168\u7684\u4e8b\u4ef6\u53d1\u5c04\u5668\uff1a<\/p>\n<pre><code class=\"language-typescript\">\ninterface WindowEventMap {\n    resize: UIEvent;\n    scroll: Event;\n    click: MouseEvent;\n}\n\ntype EventName = keyof WindowEventMap;\n\ntype Listener&lt;T&gt; = (event: T) =&gt; void;\n\nclass TypedEventEmitter {\n    private listeners: { [K in EventName]?: Listener&lt;WindowEventMap[K]&gt;[] } = {};\n\n    on&lt;K extends EventName&gt;(event: K, listener: Listener&lt;WindowEventMap[K]&gt;): void {\n        if (!this.listeners[event]) {\n            this.listeners[event] = [];\n        }\n        this.listeners[event]!.push(listener);\n    }\n\n    emit&lt;K extends EventName&gt;(event: K, payload: WindowEventMap[K]): void {\n        this.listeners[event]?.forEach(listener =&gt; listener(payload));\n    }\n}\n\n\/\/ \u4f7f\u7528\nconst emitter = new TypedEventEmitter();\nemitter.on(&#x27;click&#x27;, (e) =&gt; {\n    \/\/ e \u7684\u7c7b\u578b\u662f MouseEvent\n    console.log(e.clientX);\n});\n<\/code><\/pre>\n<h3>\u9ad8\u7ea7\u6a21\u5f0f\uff1a\u63a8\u65ad\u5b57\u7b26\u4e32\u7ed3\u6784<\/h3>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6a21\u677f\u5b57\u9762\u91cf\u7c7b\u578b\u6765\u89e3\u6790\u8def\u5f84\u6216\u67e5\u8be2\u53c2\u6570\uff1a<\/p>\n<pre><code class=\"language-typescript\">\ntype ParsePath&lt;T extends string&gt; = T extends `${infer First}\/${infer Rest}` ?\n    [First, ...ParsePath&lt;Rest&gt;] : [T];\n\ntype PathParts = ParsePath&lt;&#x27;\/user\/profile\/settings&#x27;&gt;; \/\/ [&#x27;user&#x27;, &#x27;profile&#x27;, &#x27;settings&#x27;]\n<\/code><\/pre>\n<p><strong>\ud83d\udca1 \u63d0\u793a<\/strong>\uff1a\u6a21\u677f\u5b57\u9762\u91cf\u7c7b\u578b\u975e\u5e38\u9002\u5408\u7528\u4e8e\u6784\u5efa\u7c7b\u578b\u5b89\u5168\u7684 DSL\uff08\u9886\u57df\u7279\u5b9a\u8bed\u8a00\uff09\uff0c\u6bd4\u5982\u8def\u7531\u5b9a\u4e49\u6216\u6570\u636e\u5e93\u67e5\u8be2\u6784\u5efa\u5668\u3002<\/p>\n<h2>3. \u88c5\u9970\u5668\uff1a\u65b0\u6807\u51c6\u4e0b\u7684\u5143\u7f16\u7a0b<\/h2>\n<p>TypeScript 5.0 \u5b9e\u73b0\u4e86\u65b0\u7684\u88c5\u9970\u5668\u6807\u51c6\uff08ECMAScript 2023\uff09\uff0c\u4e0e\u65e7\u7248\u88c5\u9970\u5668\u6709\u5f88\u5927\u533a\u522b\u3002\u65b0\u88c5\u9970\u5668\u66f4\u7075\u6d3b\uff0c\u4e14\u652f\u6301\u7c7b\u578b\u5b89\u5168\u7684\u88c5\u9970\u5668\u5de5\u5382\u3002<\/p>\n<h3>\u65b0\u88c5\u9970\u5668\u57fa\u7840<\/h3>\n<p>\u5728 TypeScript 5.0 \u4e2d\uff0c\u88c5\u9970\u5668\u73b0\u5728\u53ef\u4ee5\u7528\u4e8e\u7c7b\u3001\u65b9\u6cd5\u3001\u5c5e\u6027\u548c\u53c2\u6570\u3002\u6211\u4eec\u4ee5\u65b9\u6cd5\u88c5\u9970\u5668\u4e3a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-typescript\">\nfunction logMethod(target: Function, context: ClassMethodDecoratorContext) {\n    return function (this: any, ...args: any[]) {\n        console.log(`Calling ${context.name} with`, args);\n        return target.apply(this, args);\n    };\n}\n\nclass Calculator {\n    @logMethod\n    add(a: number, b: number): number {\n        return a + b;\n    }\n}\n\nconst calc = new Calculator();\ncalc.add(1, 2); \/\/ \u8f93\u51fa: Calling add with [1, 2]\n<\/code><\/pre>\n<h3>\u88c5\u9970\u5668\u5de5\u5382\uff1a\u53c2\u6570\u5316\u88c5\u9970\u5668<\/h3>\n<p>\u65b0\u88c5\u9970\u5668\u652f\u6301\u5de5\u5382\u6a21\u5f0f\uff0c\u53ef\u4ee5\u4f20\u5165\u53c2\u6570\uff1a<\/p>\n<pre><code class=\"language-typescript\">\nfunction logMethod(prefix: string) {\n    return function (target: Function, context: ClassMethodDecoratorContext) {\n        return function (this: any, ...args: any[]) {\n            console.log(`${prefix} - Calling ${context.name}`);\n            return target.apply(this, args);\n        };\n    };\n}\n\nclass Calculator {\n    @logMethod(&#x27;DEBUG&#x27;)\n    add(a: number, b: number): number {\n        return a + b;\n    }\n}\n<\/code><\/pre>\n<h3>\u5b9e\u6218\uff1a\u4f9d\u8d56\u6ce8\u5165\u88c5\u9970\u5668<\/h3>\n<p>\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u88c5\u9970\u5668\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u4f9d\u8d56\u6ce8\u5165\u5bb9\u5668\uff1a<\/p>\n<pre><code class=\"language-typescript\">\nimport &#x27;reflect-metadata&#x27;;\n\nconst SERVICE_KEY = Symbol(&#x27;service&#x27;);\n\nfunction Injectable() {\n    return function (target: any) {\n        Reflect.defineMetadata(SERVICE_KEY, true, target);\n    };\n}\n\nfunction Inject(service: any) {\n    return function (target: any, key: string | symbol, index?: number) {\n        const existing = Reflect.getMetadata(&#x27;design:paramtypes&#x27;, target) || [];\n        existing[index!] = service;\n        Reflect.defineMetadata(&#x27;design:paramtypes&#x27;, existing, target);\n    };\n}\n\nclass Container {\n    private instances = new Map&lt;string, any&gt;();\n\n    register&lt;T&gt;(token: string, implementation: new (...args: any[]) =&gt; T) {\n        const paramTypes = Reflect.getMetadata(&#x27;design:paramtypes&#x27;, implementation) || [];\n        const params = paramTypes.map((type: any) =&gt; this.resolve(type));\n        this.instances.set(token, new implementation(...params));\n    }\n\n    resolve&lt;T&gt;(token: string | (new (...args: any[]) =&gt; T)): T {\n        if (typeof token === &#x27;string&#x27;) {\n            return this.instances.get(token);\n        }\n        \/\/ \u5b9e\u73b0\u89e3\u6790\u903b\u8f91\n    }\n}\n\n@Injectable()\nclass DatabaseService {\n    connect() { }\n}\n\n@Injectable()\nclass UserService {\n    constructor(@Inject(DatabaseService) private db: DatabaseService) { }\n}\n\n\/\/ \u4f7f\u7528\u5bb9\u5668\u6ce8\u518c\nconst container = new Container();\ncontainer.register(&#x27;UserService&#x27;, UserService);\n<\/code><\/pre>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u65b0\u88c5\u9970\u5668\u9700\u8981 <code>experimentalDecorators<\/code> \u9009\u9879\u5173\u95ed\uff0c\u5e76\u5728 <code>tsconfig.json<\/code> \u4e2d\u5f00\u542f <code>target: ES2022<\/code> \u6216\u66f4\u9ad8\u3002<\/p>\n<h2>4. \u5176\u4ed6\u8fdb\u9636\u7279\u6027<\/h2>\n<h3>4.1 <code>satisfies<\/code> \u8fd0\u7b97\u7b26<\/h3>\n<p><code>satisfies<\/code> \u8fd0\u7b97\u7b26\uff08TypeScript 4.9 \u5f15\u5165\uff09\u786e\u4fdd\u8868\u8fbe\u5f0f\u6ee1\u8db3\u67d0\u4e2a\u7c7b\u578b\uff0c\u540c\u65f6\u4fdd\u7559\u66f4\u5177\u4f53\u7684\u7c7b\u578b\u63a8\u65ad\uff1a<\/p>\n<pre><code class=\"language-typescript\">\nconst config = {\n    port: 3000,\n    host: &#x27;localhost&#x27;\n} satisfies Record&lt;string, string | number&gt;;\n\nconfig.port.toFixed(); \/\/ \u6b63\u786e\uff0cport \u63a8\u65ad\u4e3a number\n<\/code><\/pre>\n<h3>4.2 <code>using<\/code> \u58f0\u660e\uff08\u663e\u5f0f\u8d44\u6e90\u7ba1\u7406\uff09<\/h3>\n<p>TypeScript 5.2 \u5f15\u5165\u4e86 <code>using<\/code> \u58f0\u660e\uff0c\u7528\u4e8e\u7ba1\u7406\u8d44\u6e90\u751f\u547d\u5468\u671f\uff1a<\/p>\n<pre><code class=\"language-typescript\">\nclass FileResource {\n    constructor(private path: string) {}\n    [Symbol.dispose]() {\n        console.log(`Closing file ${this.path}`);\n    }\n}\n\nfunction readFile(path: string) {\n    using file = new FileResource(path);\n    \/\/ \u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\n}\n\nreadFile(&#x27;data.txt&#x27;); \/\/ \u81ea\u52a8\u8c03\u7528 dispose\n<\/code><\/pre>\n<h3>4.3 \u88c5\u9970\u5668\u5143\u6570\u636e<\/h3>\n<p>\u65b0\u88c5\u9970\u5668\u6807\u51c6\u652f\u6301\u5143\u6570\u636e\u53cd\u5c04\uff0c\u7ed3\u5408 <code>reflect-metadata<\/code> \u53ef\u4ee5\u66f4\u4f18\u96c5\u5730\u5b9e\u73b0\u4f9d\u8d56\u6ce8\u5165\u3002<\/p>\n<h2>5. \u5b9e\u6218\uff1a\u6784\u5efa\u4e00\u4e2a\u7c7b\u578b\u5b89\u5168\u7684\u914d\u7f6e\u7ba1\u7406\u5668<\/h2>\n<p>\u8ba9\u6211\u4eec\u7efc\u5408\u8fd0\u7528\u4ee5\u4e0a\u7279\u6027\uff0c\u6784\u5efa\u4e00\u4e2a\u7c7b\u578b\u5b89\u5168\u7684\u914d\u7f6e\u7ba1\u7406\u5668\u3002<\/p>\n<pre><code class=\"language-typescript\">\n\/\/ config.ts\nimport &#x27;reflect-metadata&#x27;;\n\ntype ConfigValue = string | number | boolean;\n\ninterface ConfigSchema {\n    [key: string]: ConfigValue;\n}\n\nclass ConfigManager&lt;T extends ConfigSchema&gt; {\n    private config: T;\n\n    constructor(schema: T) {\n        this.config = schema;\n    }\n\n    get&lt;K extends keyof T&gt;(key: K): T[K] {\n        return this.config[key];\n    }\n\n    set&lt;K extends keyof T&gt;(key: K, value: T[K]): void {\n        this.config[key] = value;\n    }\n\n    \/\/ \u4f7f\u7528\u6a21\u677f\u5b57\u9762\u91cf\u7c7b\u578b\u652f\u6301\u5d4c\u5957\u8def\u5f84\n    getPath&lt;P extends string&gt;(path: P): P extends `${infer K}.${infer R}` ? \n        (K extends keyof T ? T[K] extends object ? ConfigManager&lt;T[K]&gt;[&#x27;getPath&#x27;]&lt;R&gt; : never : never) : T[P];\n}\n\n\/\/ \u4f7f\u7528\u793a\u4f8b\nconst config = new ConfigManager({\n    server: {\n        port: 3000,\n        host: &#x27;localhost&#x27;\n    },\n    debug: true\n});\n\nconst port = config.get(&#x27;server&#x27;).get(&#x27;port&#x27;); \/\/ number\n<\/code><\/pre>\n<h2>6. \u5e38\u89c1\u5751\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h2>\n<h3>\u57511\uff1a\u88c5\u9970\u5668\u987a\u5e8f<\/h3>\n<p>\u65b0\u88c5\u9970\u5668\u7684\u6267\u884c\u987a\u5e8f\u4e0e\u65e7\u7248\u4e0d\u540c\uff0c\u9700\u8981\u6ce8\u610f\u3002<\/p>\n<h3>\u57512\uff1a<code>const<\/code> \u7c7b\u578b\u53c2\u6570\u4e0e\u53ef\u53d8\u6027<\/h3>\n<p><code>const<\/code> \u7c7b\u578b\u53c2\u6570\u63a8\u65ad\u51fa\u7684\u7c7b\u578b\u662f <code>readonly<\/code> \u7684\uff0c\u5982\u679c\u540e\u7eed\u9700\u8981\u4fee\u6539\uff0c\u9700\u8981\u5c0f\u5fc3\u3002<\/p>\n<h3>\u6700\u4f73\u5b9e\u8df5<\/h3>\n<ul>\n<li>\u5728\u5e93\u5f00\u53d1\u4e2d\u5927\u91cf\u4f7f\u7528 <code>const<\/code> \u7c7b\u578b\u53c2\u6570\u548c\u6a21\u677f\u5b57\u9762\u91cf\u7c7b\u578b\uff0c\u63d0\u4f9b\u66f4\u7cbe\u786e\u7684\u7c7b\u578b\u63a8\u65ad\u3002<\/li>\n<li>\u5229\u7528\u88c5\u9970\u5668\u5b9e\u73b0\u6a2a\u5207\u5173\u6ce8\u70b9\uff0c\u5982\u65e5\u5fd7\u3001\u7f13\u5b58\u3001\u6743\u9650\u63a7\u5236\u3002<\/li>\n<li>\u4f7f\u7528 <code>satisfies<\/code> \u4ee3\u66ff\u7c7b\u578b\u65ad\u8a00\uff0c\u4fdd\u7559\u7c7b\u578b\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<h2>\u603b\u7ed3<\/h2>\n<p>TypeScript 5.x \u7684\u8fdb\u9636\u7279\u6027\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u7c7b\u578b\u7cfb\u7edf\u548c\u5143\u7f16\u7a0b\u80fd\u529b\u3002\u901a\u8fc7\u5408\u7406\u8fd0\u7528 <code>const<\/code> \u7c7b\u578b\u53c2\u6570\u3001\u6a21\u677f\u5b57\u9762\u91cf\u7c7b\u578b\u3001\u88c5\u9970\u5668\u7b49\uff0c\u6211\u4eec\u53ef\u4ee5\u663e\u8457\u63d0\u5347\u4ee3\u7801\u7684\u7c7b\u578b\u5b89\u5168\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u4f60\u638c\u63e1\u8fd9\u4e9b\u8fdb\u9636\u7528\u6cd5\uff0c\u5e76\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u53d1\u6325\u4f5c\u7528\u3002<\/p>\n<p>\u4e0b\u4e00\u6b65\uff0c\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u5c06\u8fd9\u4e9b\u7279\u6027\u5e94\u7528\u5230\u81ea\u5df1\u7684\u9879\u76ee\u4e2d\uff0c\u6216\u8005\u6df1\u5165\u5b66\u4e60\u88c5\u9970\u5668\u5143\u6570\u636e\u4e0e\u4f9d\u8d56\u6ce8\u5165\u7684\u7ed3\u5408\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u6df1\u5165\u63a2\u8ba8 TypeScript 5.x \u7684\u8fdb\u9636\u7279\u6027\uff0c\u5305\u62ec const \u7c7b\u578b\u53c2\u6570\u3001\u6a21\u677f\u5b57\u9762\u91cf\u7c7b\u578b\u3001\u88c5\u9970\u5668\u65b0\u6807\u51c6\u7b49\uff0c\u901a\u8fc7\u5b9e\u6218\u793a\u4f8b\u5c55\u793a\u5982\u4f55\u5229\u7528\u8fd9\u4e9b\u7279\u6027\u7f16\u5199\u66f4\u5b89\u5168\u3001\u66f4\u7075\u6d3b\u7684\u4ee3\u7801\uff0c\u63d0\u5347\u5f00\u53d1\u6548\u7387\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[40,175,174,129,176],"class_list":["post-225","post","type-post","status-publish","format-standard","hentry","category-3","category-4","tag-typescript","tag-175","tag-174","tag-129","tag-176"],"_links":{"self":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=225"}],"version-history":[{"count":0,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/225\/revisions"}],"wp:attachment":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}