Skip to content

Bug: tsc crash TypeError: Cannot read property 'flags' of undefined #25264

Closed
@purificant

Description

@purificant

TypeScript Version: 2.9.2 and typescript@next at the time of writing.

Search Terms: TypeError: Cannot read property 'flags' of undefined

Code

class Abstract {
  protected constructor() {
  }
}

class Concrete extends Abstract {
}

type Constructor<T = {}> = new (...args: any[]) => T;

function Mixin<TBase extends Constructor>(Base: TBase) {
  return class extends Base {
  };
}

class Empty {
}

class CrashTrigger extends Mixin(Empty) {
  public trigger() {
    new Concrete();
  }
}

Example repo with code to reproduce: https://github.com/purificant/typescript-crash-example

Expected behavior:
tsc emits an error along the lines of "TS2674: Constructor of class 'Abstract' is protected and only accessible within the class declaration."

Actual behavior:
tsc crashes with the following stack trace:

typescript-crash-example/node_modules/typescript/lib/tsc.js:63860
                throw e;
                ^

TypeError: Cannot read property 'flags' of undefined
    at getBaseTypes (typescript-crash-example/node_modules/typescript/lib/tsc.js:25683:38)
    at isConstructorAccessible (typescript-crash-example/node_modules/typescript/lib/tsc.js:36070:37)
    at resolveNewExpression (typescript-crash-example/node_modules/typescript/lib/tsc.js:36024:22)
    at resolveSignature (typescript-crash-example/node_modules/typescript/lib/tsc.js:36180:28)
    at getResolvedSignature (typescript-crash-example/node_modules/typescript/lib/tsc.js:36209:26)
    at checkCallExpression (typescript-crash-example/node_modules/typescript/lib/tsc.js:36282:29)
    at checkExpressionWorker (typescript-crash-example/node_modules/typescript/lib/tsc.js:37687:28)
    at checkExpression (typescript-crash-example/node_modules/typescript/lib/tsc.js:37629:42)
    at checkExpressionStatement (typescript-crash-example/node_modules/typescript/lib/tsc.js:39545:13)
    at checkSourceElement (typescript-crash-example/node_modules/typescript/lib/tsc.js:41180:28)

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions