Skip to content

Commit eb8ec88

Browse files
committed
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
1 parent f29aeb9 commit eb8ec88

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

‎tsc/internal/bundled/libs/lib.decorators.d.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,19 @@ interface ClassDecoratorContext<
5353
*
5454
* @example
5555
* ```ts
56-
* function customElement(name: string): ClassDecoratorFunction {
57-
* return (target, context) => {
56+
* function customElement(name: string) {
57+
* return <Class extends CustomElementConstructor>(
58+
* target: Class,
59+
* context: ClassDecoratorContext<Class>,
60+
* ) => {
5861
* context.addInitializer(function () {
5962
* customElements.define(name, this);
6063
* });
61-
* }
64+
* };
6265
* }
6366
*
6467
* @customElement("my-element")
65-
* class MyElement {}
68+
* class MyElement extends HTMLElement {}
6669
* ```
6770
*/
6871
addInitializer(initializer: (this: Class) => void): void;
@@ -114,10 +117,14 @@ interface ClassMethodDecoratorContext<
114117
*
115118
* @example
116119
* ```ts
117-
* const bound: ClassMethodDecoratorFunction = (value, context) {
120+
* function bound<This, Value extends (...args: any) => any>(
121+
* value: Value,
122+
* context: ClassMethodDecoratorContext<This, Value>,
123+
* ) {
118124
* if (context.private) throw new TypeError("Not supported on private methods.");
119-
* context.addInitializer(function () {
120-
* this[context.name] = this[context.name].bind(this);
125+
* context.addInitializer(function (this: This) {
126+
* const self = this as Record<PropertyKey, any>;
127+
* self[context.name] = self[context.name].bind(this);
121128
* });
122129
* }
123130
*

0 commit comments

Comments
 (0)