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: Strange incompatibility between correct and incorrect import of same type #21653

Open
ghost opened this issue Feb 5, 2018 · 4 comments
Labels
Domain: Error Messages The issue relates to error messaging Experience Enhancement Noncontroversial enhancements In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Milestone

Comments

@ghost
Copy link

ghost commented Feb 5, 2018

TypeScript Version: master

Code

b.d.ts

declare class C {
    f: this;
}
declare namespace C {}
export = C;

a.ts

import * as C1 from "./b";
import C2 = require("./b");

function f(t: (c: C1) => void): void {
    t(new C2());
}

Expected behavior:

Error at import * as C1.

Actual behavior:

No error at the import declaration. Error at new C2():

src/a.ts(5,7): error TS2345: Argument of type 'C' is not assignable to parameter of type 'C'.
  Types of property 'f' are incompatible.
    Type 'C' is not assignable to type 'this'.

(possibly related: #20704)

@ghost ghost added the Bug A bug in TypeScript label Feb 5, 2018
@weswigham
Copy link
Member

weswigham commented Feb 6, 2018

This is because the redundant better-error-check in checkTypeRelatedTo doesn't apply to contravariant failures right now. See ~lines 9384. It only checks if the source had an originating import and an unmangled type - to handle contravariant positions, the target should be checked as well. Not related to #20704, I don't think.

@mhegazy mhegazy added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Bug A bug in TypeScript labels Feb 6, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@ghost
Copy link
Author

ghost commented Feb 20, 2018

@weswigham It sounded like there was a potential fix for this? Should we keep this issue around?

@weswigham
Copy link
Member

There's definitely a potential fix. The current implementation just doesn't handle checking for a better error for contravariant comparisons.

@ghost ghost reopened this Feb 20, 2018
@ghost ghost added Domain: Error Messages The issue relates to error messaging Suggestion An idea for TypeScript and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Feb 20, 2018
@RyanCavanaugh RyanCavanaugh added the Experience Enhancement Noncontroversial enhancements label Aug 22, 2018
@weswigham weswigham added the In Discussion Not yet reached consensus label Nov 6, 2018
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Aug 16, 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 Experience Enhancement Noncontroversial enhancements In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants