-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Improve non-ambient class and function merge error #33441
Conversation
: undefined; | ||
if (diagnostic) { | ||
addRelatedInfo( | ||
error(getNameOfDeclaration(declaration) || declaration, diagnostic, symbolName(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.
Is it safe to provide symbolName(symbol)
even if the diagnostic doesn't specify a parameter?
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.
Yep, from reading the code, it looks for the params in the string and matches the values to that - basically it'll just not do anything 👍
export function formatStringFromArgs(text: string, args: ArrayLike<string | number>, baseIndex = 0): string {
return text.replace(/{(\d+)}/g, (_match, index: string) => "" + Debug.assertDefined(args[+index + baseIndex]));
}
"category": "Error", | ||
"code": 2774 | ||
}, | ||
"Function with bodies can only merge with classes that are ambient.": { |
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.
Is "bodies" right? Or can there only be one function body?
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.
Good point, there's only one body, I think we should probably make these two error messages:
Class declaration cannot implement overload list for '{0}'.
Functions with bodies can only merge with classes that are ambient.
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.
Looking good! Only some minor wording changes 👍
: undefined; | ||
if (diagnostic) { | ||
addRelatedInfo( | ||
error(getNameOfDeclaration(declaration) || declaration, diagnostic, symbolName(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.
Yep, from reading the code, it looks for the params in the string and matches the values to that - basically it'll just not do anything 👍
export function formatStringFromArgs(text: string, args: ArrayLike<string | number>, baseIndex = 0): string {
return text.replace(/{(\d+)}/g, (_match, index: string) => "" + Debug.assertDefined(args[+index + baseIndex]));
}
"category": "Error", | ||
"code": 2774 | ||
}, | ||
"Function with bodies can only merge with classes that are ambient.": { |
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.
Good point, there's only one body, I think we should probably make these two error messages:
Class declaration cannot implement overload list for '{0}'.
Functions with bodies can only merge with classes that are ambient.
Poke ^ |
Hi @austincummings - this PR didn't have 'allow maintainers to make changes' checked, and so when we migrated TypeScript's primary branch from 'master' to 'main' this PR couldn't have its branch re-targeted. It looks like most of my changes were cosmetics, so once I've got my current PR up and running, I'll replicate this PR with my changes included and get it reviewed 👍🏻 |
Fixes #32795