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

esmoduleinterop: Improve error message when calling static method on class #21656

Open
ghost opened this issue Feb 6, 2018 · 3 comments
Open
Labels
Domain: Error Messages The issue relates to error messaging Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@ghost
Copy link

ghost commented Feb 6, 2018

TypeScript Version: master

Code

b.d.ts:

declare class C { static m(): void }
declare namespace C {}
export = C;
import * as C from "./b";
C.m();

Expected behavior:

src/a.ts(1,1): error TS7038: A namespace-style import will import a module namespace object, not a class.
src/a.ts(2,3): error TS2339: Property 'm' does not exist on type 'typeof C'.

Actual behavior:

src/a.ts(2,3): error TS2339: Property 'm' does not exist on type 'typeof C'.

@ghost ghost added Suggestion An idea for TypeScript Domain: Error Messages The issue relates to error messaging labels Feb 6, 2018
@ghost
Copy link
Author

ghost commented Feb 6, 2018

It would be nice if we did this when constructing a JSX node too. For import * as C ... <C> </C> we should add an error at the import statement.

@weswigham
Copy link
Member

Also maybe

src/a.ts(2,3): error TS2339: Property 'm' does not exist on type 'typeof C'. Did you mean `C.default.m()`?

?
At least if another diagnostic code is added for this situation, then the quickfix can be updated to propose that fix. That's a simple change of checking if there's a property does-not-exist error, then check if there's a default and default has that member. If so, issue the alternate diagnostic, otherwise issue the normal one. (Technically this could be generalized to suggesting members within non-default-named members if the other name lines up, but I don't think that's quite as useful)

@mhegazy mhegazy added this to the Community milestone Feb 6, 2018
@mhegazy mhegazy added the Help Wanted You can do this label Feb 6, 2018
@ghost
Copy link
Author

ghost commented Feb 6, 2018

Similar for use in instanceof.

@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Error Messages The issue relates to error messaging Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants