镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

AllowJs + ES6 lib result in compiler crash #40251

Description

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

Activity

  1. frank-dspeed commented on Aug 27, 2020

    @frank-dspeed

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

  2. JimmyPruitt commented on Aug 27, 2020

    @JimmyPruitt
    Author

    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?

  3. added
    RescheduledThis issue was previously scheduled to an earlier milestone
    and removed
    RescheduledThis issue was previously scheduled to an earlier milestone
    on Aug 31, 2020
  4. added a commit that references this issue on Oct 27, 2020
    268a409
  5. ahejlsberg commented on Oct 28, 2020

    @ahejlsberg
    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.

  6. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions