Skip to content

Commit

Permalink
fix: typeof this usage in classes should not alias to `typeof this$…
Browse files Browse the repository at this point in the history
…1` (#287)

Closes #279
  • Loading branch information
crutchcorn committed Sep 10, 2023
1 parent ff39e68 commit bbb85f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/transform/DeclarationScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export class DeclarationScope {
}
}
}
// `this` is a reserved keyword that retrains meaning in certain Type-only contexts, including classes
if (name === "this") return;
const { ident, expr } = createReference(id);

this.declaration.params.push(expr);
Expand Down
4 changes: 4 additions & 0 deletions tests/testcases/type-typeof-this/expected.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare class NumberSchema {
min: () => typeof this;
}
export { NumberSchema };
3 changes: 3 additions & 0 deletions tests/testcases/type-typeof-this/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class NumberSchema {
min: () => typeof this;
}

0 comments on commit bbb85f1

Please sign in to comment.