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

AllowJs + ES6 lib result in compiler crash #40251

Closed
JimmyPruitt opened this issue Aug 25, 2020 · 3 comments · Fixed by #41308
Closed

AllowJs + ES6 lib result in compiler crash #40251

JimmyPruitt opened this issue Aug 25, 2020 · 3 comments · Fixed by #41308
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@JimmyPruitt
Copy link

JimmyPruitt commented Aug 25, 2020

TypeScript Version: 4.0.2

Search Terms:
typescript Cannot read property 'name' of undefined

Code
For reasons beyond my control, my team has a few node modules checked into our code that we subsequently run through the Typescript compiler as a part of building our front end through the ts-loader Webpack loader. We can probably work around this on our end because this case is special, but I'm reporting this because I have a hunch that there could be other legitimate cases that fall to the same error. Here's a minimal package.json and tsconfig.json that I can use to recreate the problem:

{
  "name": "broken-typescript",
  "version": "1.0.0",
  "scripts": {
    "build": "tsc -p tsconfig.json"
  },
  "dependencies": {
    "@okta/okta-signin-widget": "4.3.3",
    "typescript": "4.0.2"
  }
}
{
  "compilerOptions": {
    "rootDir": "./",
    "outDir": "out",
    "allowJs": true,
    "strict": true,
    "lib": ["es6"]
  },
  "include": [
    "./node_modules/@okta/okta-signin-widget/dist/js/okta-sign-in.js"
  ]
}

Just npm i && npm run build and you'll see the error

Expected behavior:
The compiler finishes without failure

Actual behavior:
An error gets thrown:

TypeError: Cannot read property 'name' of undefined
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 26, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.1.0 milestone Aug 26, 2020
@frank-dspeed
Copy link

That is because https://unpkg.com/browse/@okta/[email protected]/dist/js/okta-sign-in.js is not a JS Module its a webpack module TS does not support importing webpack modules at present.

@JimmyPruitt
Copy link
Author

JimmyPruitt commented Aug 27, 2020

The same module works in version 3.9 of Typescript. If you change the TS version in that package ☝️ to 3.9.7 and run npm i && npm build, there are no errors and a file is emitted to the correct directory. Are you saying that this was an undocumented breaking change of version 4?

@RyanCavanaugh RyanCavanaugh added Rescheduled This issue was previously scheduled to an earlier milestone and removed Rescheduled This issue was previously scheduled to an earlier milestone labels Aug 31, 2020
@sheetalkamat sheetalkamat added the Fix Available A PR has been opened for this issue label Oct 27, 2020
@ahejlsberg
Copy link
Member

The root issue is that this produces an error:

declare let s: (...items: never[]) => never[];
let t: () => unknown[] = s;  // Error, but should be ok

To make matters worse, when attempting to report the erroneous error, we crash if there's a rest parameter:

declare let s: (...items: never[]) => never[];
let t: (...args: []) => unknown[] = s;  // Crash

The issue only occurs with a rest parameter of type never[] and it's caused by compareSignaturesRelated assuming that any (the type used for an unmatched parameter position) is assignable to anything. It is--except for never. We should change the logic to not even attempt to relate unmatched positions. I will put up a PR to that effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
5 participants