From eb8ec88acb03e4baeaba402df16add88c2f9e739 Mon Sep 17 00:00:00 2001 From: wfatih Date: Sat, 19 Sep 2026 20:45:19 +0300 Subject: [PATCH] Fix invalid decorator examples in lib.decorators.d.ts The `@example` blocks on `ClassDecoratorContext.addInitializer` and `ClassMethodDecoratorContext.addInitializer` referenced two types that do not exist: `ClassDecoratorFunction` and `ClassMethodDecoratorFunction`. The second example was also syntactically invalid (a function expression without `=>`), so neither snippet could be copied into an editor. Rewrite both snippets so they type check under `--strict` using the decorator context types that actually ship in this file. Fixes #54338 Fixes #54099 --- tsc/internal/bundled/libs/lib.decorators.d.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tsc/internal/bundled/libs/lib.decorators.d.ts b/tsc/internal/bundled/libs/lib.decorators.d.ts index 83d82bef2e557..1c044181d7efb 100644 --- a/tsc/internal/bundled/libs/lib.decorators.d.ts +++ b/tsc/internal/bundled/libs/lib.decorators.d.ts @@ -53,16 +53,19 @@ interface ClassDecoratorContext< * * @example * ```ts - * function customElement(name: string): ClassDecoratorFunction { - * return (target, context) => { + * function customElement(name: string) { + * return ( + * target: Class, + * context: ClassDecoratorContext, + * ) => { * context.addInitializer(function () { * customElements.define(name, this); * }); - * } + * }; * } * * @customElement("my-element") - * class MyElement {} + * class MyElement extends HTMLElement {} * ``` */ addInitializer(initializer: (this: Class) => void): void; @@ -114,10 +117,14 @@ interface ClassMethodDecoratorContext< * * @example * ```ts - * const bound: ClassMethodDecoratorFunction = (value, context) { + * function bound any>( + * value: Value, + * context: ClassMethodDecoratorContext, + * ) { * if (context.private) throw new TypeError("Not supported on private methods."); - * context.addInitializer(function () { - * this[context.name] = this[context.name].bind(this); + * context.addInitializer(function (this: This) { + * const self = this as Record; + * self[context.name] = self[context.name].bind(this); * }); * } *