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

Don't let the declaration file break compilation #32908

Closed
4 of 5 tasks
John0King opened this issue Aug 15, 2019 · 5 comments
Closed
4 of 5 tasks

Don't let the declaration file break compilation #32908

John0King opened this issue Aug 15, 2019 · 5 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@John0King
Copy link

John0King commented Aug 15, 2019

Suggestion

Don't let the declaration file break compilation.
if you write a declaration file that use --nolib, and others has duplicate global class name,
or a package depends on package depA, then package depA interface name has been renamed , then your app won't compile.

The unknowed type in .d.ts should map to any, and show a warning instead of error

Use Cases

@types/libraryA from npm :

///<reference no-default-lib />
declare console:MyConsole

and @types/libraryB from npm

///<reference lib="dom" />

I create a git repo to show how this happend, and I can not find a way to solve the problem in your own source code.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@John0King John0King changed the title Don't let the declaration file broken compilation Don't let the declaration file break compilation Aug 15, 2019
@DanielRosenwasser DanielRosenwasser added Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript labels Aug 15, 2019
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Aug 15, 2019

This would mean misspelled type names would resolve to unknown or any or whatever, which is undesirable. Consider adding a 👍 to #31894 which would allow you to state that some type name exists without knowing specifics about the implementation.

@John0King
Copy link
Author

John0King commented Aug 15, 2019

@DanielRosenwasser I think #31894 is not for this case ,
What I want to avoid is declaration file error , declaration file normally from third party, and there are some case that your app compile fine , your used third party declaration is compiled file, but it'll error when you add the declaration to your app.
yes I can edit the downloaded declaration but it's from npm so next time you download from network it won't compile again.

I think Typescipt should distinguish between source file and declaration file . source file can not have error , but declaration file can be tread like js (as long as it won't contains syntext error)

@John0King
Copy link
Author

@DanielRosenwasser I added a demo to show how this happend , it does not happend in your own source code , it happend when multiple declarion library been merge to your project.
should this be reopen ?

@fatcerberus
Copy link

Have you tried --skipLibCheck?

@John0King
Copy link
Author

@fatcerberus cool, it solve my problem 😜 . Thanks.
I never notice this options before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants