-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Refactor params for interface #42652
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
Refactor params for interface #42652
Conversation
Co-authored-by: Daniel Rosenwasser <[email protected]>
} | ||
|
||
/* Declarations in interface implementations have their own symbol so we need to go to the interface declaration | ||
to get the type from the method signature. */ |
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.
I don't understand which part gets the type from the method signature. Is it entryToDeclaration
? getSymbolForInterfaceSignature
only gets the symbol.
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.
changed comment.
if (signature) { | ||
const newSignatureParams = map(createNewParameters(signature, program, host), param => getSynthesizedDeepClone(param)); | ||
replaceParameters(signature, newSignatureParams); | ||
} | ||
replaceParameters(functionDeclaration, newFunctionDeclarationParams); |
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.
Should these branches be mutually exclusive? This looks suspicious to me.
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.
If the signature is defined, that means we were able to connect the method declaration back to it. That is, functionDeclaration
implements signature
and both should be changed. The absence of signature
simply means functionDeclaration
does not implement a method declared elsewhere (that we know of).
Co-authored-by: Daniel Rosenwasser <[email protected]>
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.
Looks good enough to go in, although a test with unions might make sense if the code fix could be available.
////interface IBar { | ||
//// method(x: number): void; | ||
////} | ||
////const x: IFoo & IBar = { |
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.
what happens with unions? Do we even get the error that triggers the codefix?
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.
There is a test refactorConvertParamsToDestructuredObject_interfaceNoUnion.ts:
https://github.com/microsoft/TypeScript/pull/42652/files#diff-bb37f20a7f9bacc80fda3468d1e6c808314c79f47e8f58dc3d55c7e3d5447360
It's a refactor so we just don't offer it.
Co-authored-by: Nathan Shively-Sanders <[email protected]>
Fixes #30418 for interfaces and type literals.
Cases for which we do not offer the refactor: