Skip to content

Types from packages are not properly used when checking JS with esModuleInterop #35188

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

Closed
stof opened this issue Nov 19, 2019 · 3 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@stof
Copy link

stof commented Nov 19, 2019

TypeScript Version: 3.8.0-dev.20191119 (same result with 3.7.2 as well)

Search Terms: types checkJS

Code

{
  "dependencies": {
    "humane-js": "3.2.2"
  },
  "devDependencies": {
    "@types/humane-js": "3.2.0",
    "typescript": "3.8.0-dev.20191119"
  }
}
// typescript.ts
import humane from 'humane-js';

humane.timeout = 4000;

export const notifyInfo = humane.spawn({ addnCls: 'humane-info' });
// javascript.js (same code than typescript.ts)
import humane from 'humane-js';

humane.timeout = 4000;

export const notifyInfo = humane.spawn({ addnCls: 'humane-info' });

Expected behavior:

Running both tsc --noEmit --esModuleInterop typescript.ts and tsc --noEmit --esModuleInterop --allowJS --checkJS javascript.js succeed.

Actual behavior:

Type-checking for the Typescript file succeeds. But type-checking for the javascript files fails with this error:

javascript.js:5:34 - error TS2339: Property 'spawn' does not exist on type 'typeof humane'.

5 export const notifyInfo = humane.spawn({ addnCls: 'humane-info' });
                                   ~~~~~


Found 1 error.

Note that if I change my JS file to use a CommonJS require call rather than an ES import and then run tsc --noEmit --allowJS --checkJS javascript.js, tsc will properly identify the type of humane (type-checking succeeds on this code, and introducing a typo in the spawn method name gets caught)

It would be great if --esModuleInterop could work when using tsc to check JS code, to allow using it to check webpack projects (which have such interop loading of JS modules).

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Dec 18, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.9.0 milestone Dec 18, 2019
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label May 20, 2020
@rbuckton
Copy link
Contributor

This seems to have been fixed by #39490 while I was making other changes.

@rbuckton
Copy link
Contributor

@stof can you verify this with tomorrows nightly to make sure it has been properly addressed?

@andrewbranch
Copy link
Member

Confirmed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

No branches or pull requests

5 participants