-
Notifications
You must be signed in to change notification settings - Fork 13.3k
fix: suppress TS4055/TS4073 for protected methods using typeof parameter #63221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
umeshmore45
wants to merge
2
commits into
microsoft:main
from
umeshmore45:fix/protected-method-typeof-parameter-ts4055
+277
−1
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/protectedMethodTypeofParameter.d.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //// [tests/cases/compiler/protectedMethodTypeofParameter.d.ts] //// | ||
|
|
||
| === protectedMethodTypeofParameter.d.ts === | ||
| export interface Properties { | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.d.ts, 0, 0)) | ||
|
|
||
| propertyA: number; | ||
| >propertyA : Symbol(Properties.propertyA, Decl(protectedMethodTypeofParameter.d.ts, 0, 29)) | ||
|
|
||
| propertyB: string; | ||
| >propertyB : Symbol(Properties.propertyB, Decl(protectedMethodTypeofParameter.d.ts, 1, 22)) | ||
| } | ||
| export declare class A { | ||
| >A : Symbol(A, Decl(protectedMethodTypeofParameter.d.ts, 3, 1)) | ||
|
|
||
| getPropertyValue_Ok(properties: Properties, propertyName: keyof Properties): Properties[typeof propertyName]; | ||
| >getPropertyValue_Ok : Symbol(A.getPropertyValue_Ok, Decl(protectedMethodTypeofParameter.d.ts, 4, 24)) | ||
| >properties : Symbol(properties, Decl(protectedMethodTypeofParameter.d.ts, 5, 24)) | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.d.ts, 0, 0)) | ||
| >propertyName : Symbol(propertyName, Decl(protectedMethodTypeofParameter.d.ts, 5, 47)) | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.d.ts, 0, 0)) | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.d.ts, 0, 0)) | ||
| >propertyName : Symbol(propertyName, Decl(protectedMethodTypeofParameter.d.ts, 5, 47)) | ||
|
|
||
| protected getPropertyValue_Error(properties: Properties, propertyName: keyof Properties): Properties[typeof propertyName]; | ||
| >getPropertyValue_Error : Symbol(A.getPropertyValue_Error, Decl(protectedMethodTypeofParameter.d.ts, 5, 113)) | ||
| >properties : Symbol(properties, Decl(protectedMethodTypeofParameter.d.ts, 6, 37)) | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.d.ts, 0, 0)) | ||
| >propertyName : Symbol(propertyName, Decl(protectedMethodTypeofParameter.d.ts, 6, 60)) | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.d.ts, 0, 0)) | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.d.ts, 0, 0)) | ||
| >propertyName : Symbol(propertyName, Decl(protectedMethodTypeofParameter.d.ts, 6, 60)) | ||
| } | ||
|
|
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/protectedMethodTypeofParameter.d.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //// [tests/cases/compiler/protectedMethodTypeofParameter.d.ts] //// | ||
|
|
||
| === protectedMethodTypeofParameter.d.ts === | ||
| export interface Properties { | ||
| propertyA: number; | ||
| >propertyA : number | ||
| > : ^^^^^^ | ||
|
|
||
| propertyB: string; | ||
| >propertyB : string | ||
| > : ^^^^^^ | ||
| } | ||
| export declare class A { | ||
| >A : A | ||
| > : ^ | ||
|
|
||
| getPropertyValue_Ok(properties: Properties, propertyName: keyof Properties): Properties[typeof propertyName]; | ||
| >getPropertyValue_Ok : (properties: Properties, propertyName: keyof Properties) => Properties[typeof propertyName] | ||
| > : ^ ^^ ^^ ^^ ^^^^^ | ||
| >properties : Properties | ||
| > : ^^^^^^^^^^ | ||
| >propertyName : keyof Properties | ||
| > : ^^^^^^^^^^^^^^^^ | ||
| >propertyName : keyof Properties | ||
| > : ^^^^^^^^^^^^^^^^ | ||
|
|
||
| protected getPropertyValue_Error(properties: Properties, propertyName: keyof Properties): Properties[typeof propertyName]; | ||
| >getPropertyValue_Error : (properties: Properties, propertyName: keyof Properties) => Properties[typeof propertyName] | ||
| > : ^ ^^ ^^ ^^ ^^^^^ | ||
| >properties : Properties | ||
| > : ^^^^^^^^^^ | ||
| >propertyName : keyof Properties | ||
| > : ^^^^^^^^^^^^^^^^ | ||
| >propertyName : keyof Properties | ||
| > : ^^^^^^^^^^^^^^^^ | ||
| } | ||
|
|
45 changes: 45 additions & 0 deletions
45
tests/baselines/reference/protectedMethodTypeofParameter.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| //// [tests/cases/compiler/protectedMethodTypeofParameter.ts] //// | ||
|
|
||
| //// [protectedMethodTypeofParameter.ts] | ||
| export interface Properties { | ||
| propertyA: number; | ||
| propertyB: string; | ||
| } | ||
|
|
||
| export class A { | ||
| public getPropertyValue_Ok( | ||
| properties: Properties, | ||
| propertyName: keyof Properties, | ||
| ): Properties[typeof propertyName] { | ||
| return properties[propertyName]; | ||
| } | ||
|
|
||
| protected getPropertyValue_Error( | ||
| properties: Properties, | ||
| propertyName: keyof Properties, | ||
| ): Properties[typeof propertyName] { | ||
| return properties[propertyName]; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| //// [protectedMethodTypeofParameter.js] | ||
| export class A { | ||
| getPropertyValue_Ok(properties, propertyName) { | ||
| return properties[propertyName]; | ||
| } | ||
| getPropertyValue_Error(properties, propertyName) { | ||
| return properties[propertyName]; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| //// [protectedMethodTypeofParameter.d.ts] | ||
| export interface Properties { | ||
| propertyA: number; | ||
| propertyB: string; | ||
| } | ||
| export declare class A { | ||
| getPropertyValue_Ok(properties: Properties, propertyName: keyof Properties): Properties[typeof propertyName]; | ||
| protected getPropertyValue_Error(properties: Properties, propertyName: keyof Properties): Properties[typeof propertyName]; | ||
| } |
57 changes: 57 additions & 0 deletions
57
tests/baselines/reference/protectedMethodTypeofParameter.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //// [tests/cases/compiler/protectedMethodTypeofParameter.ts] //// | ||
|
|
||
| === protectedMethodTypeofParameter.ts === | ||
| export interface Properties { | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.ts, 0, 0)) | ||
|
|
||
| propertyA: number; | ||
| >propertyA : Symbol(Properties.propertyA, Decl(protectedMethodTypeofParameter.ts, 0, 29)) | ||
|
|
||
| propertyB: string; | ||
| >propertyB : Symbol(Properties.propertyB, Decl(protectedMethodTypeofParameter.ts, 1, 20)) | ||
| } | ||
|
|
||
| export class A { | ||
| >A : Symbol(A, Decl(protectedMethodTypeofParameter.ts, 3, 1)) | ||
|
|
||
| public getPropertyValue_Ok( | ||
| >getPropertyValue_Ok : Symbol(A.getPropertyValue_Ok, Decl(protectedMethodTypeofParameter.ts, 5, 16)) | ||
|
|
||
| properties: Properties, | ||
| >properties : Symbol(properties, Decl(protectedMethodTypeofParameter.ts, 6, 29)) | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.ts, 0, 0)) | ||
|
|
||
| propertyName: keyof Properties, | ||
| >propertyName : Symbol(propertyName, Decl(protectedMethodTypeofParameter.ts, 7, 27)) | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.ts, 0, 0)) | ||
|
|
||
| ): Properties[typeof propertyName] { | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.ts, 0, 0)) | ||
| >propertyName : Symbol(propertyName, Decl(protectedMethodTypeofParameter.ts, 7, 27)) | ||
|
|
||
| return properties[propertyName]; | ||
| >properties : Symbol(properties, Decl(protectedMethodTypeofParameter.ts, 6, 29)) | ||
| >propertyName : Symbol(propertyName, Decl(protectedMethodTypeofParameter.ts, 7, 27)) | ||
| } | ||
|
|
||
| protected getPropertyValue_Error( | ||
| >getPropertyValue_Error : Symbol(A.getPropertyValue_Error, Decl(protectedMethodTypeofParameter.ts, 11, 3)) | ||
|
|
||
| properties: Properties, | ||
| >properties : Symbol(properties, Decl(protectedMethodTypeofParameter.ts, 13, 35)) | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.ts, 0, 0)) | ||
|
|
||
| propertyName: keyof Properties, | ||
| >propertyName : Symbol(propertyName, Decl(protectedMethodTypeofParameter.ts, 14, 27)) | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.ts, 0, 0)) | ||
|
|
||
| ): Properties[typeof propertyName] { | ||
| >Properties : Symbol(Properties, Decl(protectedMethodTypeofParameter.ts, 0, 0)) | ||
| >propertyName : Symbol(propertyName, Decl(protectedMethodTypeofParameter.ts, 14, 27)) | ||
|
|
||
| return properties[propertyName]; | ||
| >properties : Symbol(properties, Decl(protectedMethodTypeofParameter.ts, 13, 35)) | ||
| >propertyName : Symbol(propertyName, Decl(protectedMethodTypeofParameter.ts, 14, 27)) | ||
| } | ||
| } | ||
|
|
68 changes: 68 additions & 0 deletions
68
tests/baselines/reference/protectedMethodTypeofParameter.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| //// [tests/cases/compiler/protectedMethodTypeofParameter.ts] //// | ||
|
|
||
| === protectedMethodTypeofParameter.ts === | ||
| export interface Properties { | ||
| propertyA: number; | ||
| >propertyA : number | ||
| > : ^^^^^^ | ||
|
|
||
| propertyB: string; | ||
| >propertyB : string | ||
| > : ^^^^^^ | ||
| } | ||
|
|
||
| export class A { | ||
| >A : A | ||
| > : ^ | ||
|
|
||
| public getPropertyValue_Ok( | ||
| >getPropertyValue_Ok : (properties: Properties, propertyName: keyof Properties) => Properties[typeof propertyName] | ||
| > : ^ ^^ ^^ ^^ ^^^^^ | ||
|
|
||
| properties: Properties, | ||
| >properties : Properties | ||
| > : ^^^^^^^^^^ | ||
|
|
||
| propertyName: keyof Properties, | ||
| >propertyName : keyof Properties | ||
| > : ^^^^^^^^^^^^^^^^ | ||
|
|
||
| ): Properties[typeof propertyName] { | ||
| >propertyName : keyof Properties | ||
| > : ^^^^^^^^^^^^^^^^ | ||
|
|
||
| return properties[propertyName]; | ||
| >properties[propertyName] : string | number | ||
| > : ^^^^^^^^^^^^^^^ | ||
| >properties : Properties | ||
| > : ^^^^^^^^^^ | ||
| >propertyName : keyof Properties | ||
| > : ^^^^^^^^^^^^^^^^ | ||
| } | ||
|
|
||
| protected getPropertyValue_Error( | ||
| >getPropertyValue_Error : (properties: Properties, propertyName: keyof Properties) => Properties[typeof propertyName] | ||
| > : ^ ^^ ^^ ^^ ^^^^^ | ||
|
|
||
| properties: Properties, | ||
| >properties : Properties | ||
| > : ^^^^^^^^^^ | ||
|
|
||
| propertyName: keyof Properties, | ||
| >propertyName : keyof Properties | ||
| > : ^^^^^^^^^^^^^^^^ | ||
|
|
||
| ): Properties[typeof propertyName] { | ||
| >propertyName : keyof Properties | ||
| > : ^^^^^^^^^^^^^^^^ | ||
|
|
||
| return properties[propertyName]; | ||
| >properties[propertyName] : string | number | ||
| > : ^^^^^^^^^^^^^^^ | ||
| >properties : Properties | ||
| > : ^^^^^^^^^^ | ||
| >propertyName : keyof Properties | ||
| > : ^^^^^^^^^^^^^^^^ | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export interface Properties { | ||
| propertyA: number; | ||
| propertyB: string; | ||
| } | ||
| export declare class A { | ||
| getPropertyValue_Ok(properties: Properties, propertyName: keyof Properties): Properties[typeof propertyName]; | ||
| protected getPropertyValue_Error(properties: Properties, propertyName: keyof Properties): Properties[typeof propertyName]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // @declaration: true | ||
|
|
||
| export interface Properties { | ||
| propertyA: number; | ||
| propertyB: string; | ||
| } | ||
|
|
||
| export class A { | ||
| public getPropertyValue_Ok( | ||
| properties: Properties, | ||
| propertyName: keyof Properties, | ||
| ): Properties[typeof propertyName] { | ||
| return properties[propertyName]; | ||
| } | ||
|
|
||
| protected getPropertyValue_Error( | ||
| properties: Properties, | ||
| propertyName: keyof Properties, | ||
| ): Properties[typeof propertyName] { | ||
| return properties[propertyName]; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new test covers the protected-method return type case, but it doesn't cover the TS4073 scenario from the issue where another parameter’s type references
typeof propertyName(e.g.propertyValue: Properties[typeof propertyName]). Adding that protected setter-style method (and asserting the.d.tscontains it without diagnostics) would prevent regressions and ensure the PR actually fixes both TS4055 and TS4073.