Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Improve non-ambient class and function merge error #33441

wants to merge 1 commit into from

Conversation

austincummings
Copy link
Contributor

Fixes #32795

: undefined;
if (diagnostic) {
addRelatedInfo(
error(getNameOfDeclaration(declaration) || declaration, diagnostic, symbolName(symbol)),
Copy link
Contributor Author

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?

Copy link
Contributor

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.": {
Copy link
Contributor Author

@austincummings austincummings Sep 16, 2019

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?

Copy link
Contributor

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.

@sandersn sandersn added the For Backlog Bug PRs that fix a backlog bug label Feb 1, 2020
Copy link
Contributor

@orta orta left a 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)),
Copy link
Contributor

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.": {
Copy link
Contributor

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.

@orta
Copy link
Contributor

orta commented Mar 27, 2020

Poke ^

@orta orta closed this May 31, 2021
@orta orta deleted the branch microsoft:master May 31, 2021 09:44
@orta
Copy link
Contributor

orta commented May 31, 2021

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 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Improve error on non-ambient class and function merge
3 participants