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

Misleading English message for error TS1046 #21251

Closed
dtgriscom opened this issue Jan 18, 2018 · 11 comments

Comments

@dtgriscom
Copy link

commented Jan 18, 2018

TypeScript Version: 2.0.10 (checked; message is the same on master branch)

Code

The following test.d.ts file:

module test {
    export const test: number;
}

when compiled, yields the following error message:

error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file.

This is both misleading and just wrong, as the following test.d.ts file is legal:

export const test: number;

Expected behavior:

The error message should not be misleading.

Actual behavior:

The error message is misleading. This led me on a wild goose chase trying to get my .d.ts file to compile, all the time using the apparently required declare statement, when the solution didn't have declare at all.

Related:

@lexcorp16

This comment has been minimized.

Copy link

commented Mar 31, 2018

Hi @DanielRosenwasser I would like to take a crack at this. This is my first attempt at contributing to open source and I will be glad if you could point me in the right directions

@mhegazy

This comment has been minimized.

Copy link

commented Apr 2, 2018

First we need a new message text proposal.

For the change itself, all messages are stored in https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json, you will need to change it and change the reference site to it in https://raw.githubusercontent.com/Microsoft/TypeScript/master/src/compiler/checker.ts (search for Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file).

@lexcorp16

This comment has been minimized.

Copy link

commented Apr 2, 2018

Thanks for getting back to me on this. Can I ask what the fix was for the issue you were having? I think that would make a suitable error message more apparent.

@DanielRosenwasser

This comment has been minimized.

Copy link
Member

commented Jun 28, 2018

I think the fix is to provide an error message like

Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.
@ely-alamillo

This comment has been minimized.

Copy link
Contributor

commented Jul 11, 2018

@DanielRosenwasser the fix for this would be to change this to Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. and then change the ref here to Top-level_declarations_in_d_ts_files_must_start_with_either_a_declare_or_export_modifier ?

@DanielRosenwasser

This comment has been minimized.

Copy link
Member

commented Jul 28, 2018

Yes, after running jake generate-diagnostics (or gulp generate-diagnostics) that should work @ely-alamillo.

@nic-hartley

This comment has been minimized.

Copy link

commented Oct 3, 2018

Doesn't look like this is being put in; does anyone mind if I do? (@lexcorp16 @ely-alamillo @DanielRosenwasser especially, since y'all either claimed it or found the fix)

@ely-alamillo

This comment has been minimized.

Copy link
Contributor

commented Oct 3, 2018

@nic-hartley I'm taking a shot at it over the weekend for hacktoberfest. If I don't have anything by 10/10 I would't mind you taking over it.

@nic-hartley

This comment has been minimized.

Copy link

commented Oct 3, 2018

@ely-alamillo Darn, there goes my plan for Hacktoberfest :)

But alright! Thanks for letting me know.

@ely-alamillo

This comment has been minimized.

Copy link
Contributor

commented Oct 11, 2018

@DanielRosenwasser would you mind pointing me in the right direction as to why the build is failing.

@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019

@nayeemrmn

This comment has been minimized.

Copy link

commented Sep 8, 2019

@DanielRosenwasser This is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.