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

Using compiled *.d.ts file produces a type error, but using the same type from the source file doesn't #29354

Open
gigobyte opened this issue Jan 10, 2019 · 1 comment
Labels
Bug A bug in TypeScript
Milestone

Comments

@gigobyte
Copy link
Contributor

gigobyte commented Jan 10, 2019

Backstory: A type error bug was reported for a library of mine. I tried reproducing by writing code inside the library source and I couldn't reproduce it. I npm install-ed my library and I could indeed see the error that was reported (I used the same code snippet in both places). Turns out the type error only happens with the compiled type definitions file.

TypeScript Version: 3.2.2

Search Terms: class property, definition file

Code

SSCCE Repo link

To reproduce: Clone the repo. Open src/BUG_HERE.ts. There will be a type error:

image

Type 'Maybe<never>' is not assignable to type 'Maybe<number>'.
  Types of property ''fantasy-land/alt'' are incompatible.
    Type '(other: Maybe<never>) => Maybe<never>' is not assignable to type '(other: Maybe<number>) => Maybe<number>'.
      Types of parameters 'other' and 'other' are incompatible.
        Type 'Maybe<number>' is not assignable to type 'Maybe<never>'.
          Types of property 'value' are incompatible.
            Type 'number | undefined' is not assignable to type 'undefined'.
              Type 'number' is not assignable to type 'undefined'.

Expected behavior:

Either both functions must have a type error or both should compile, I'm not sure which is the correct behavior, the issue is in that only the imports from the definition file produce an error.

Actual behavior:

Module imported from source has no errors, same module compiled and imported does have an error even though it's used the same way.

Observations from my research:

  • It may be related to class properties
  • Turning off --strictFunctionTypes fixes the error
@weswigham
Copy link
Member

Turning off --strictFunctionTypes fixes the error

Huh. Sounds like something that started as a method (which is checked bivariantly) gets emitted as a property (checked strictly) - potentially as a result of a simplified mapping operation (mapped types don't preserve methodiness of input props).

@weswigham weswigham added Bug A bug in TypeScript Needs Investigation This issue needs a team member to investigate its status. labels Jan 10, 2019
@RyanCavanaugh RyanCavanaugh removed the Needs Investigation This issue needs a team member to investigate its status. label Mar 7, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants