Skip to content

allowJs + declaration: Cannot read property 'parent' of undefined #33993

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
jgoz opened this issue Oct 11, 2019 · 1 comment · Fixed by #34764
Closed

allowJs + declaration: Cannot read property 'parent' of undefined #33993

jgoz opened this issue Oct 11, 2019 · 1 comment · Fixed by #34764
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue

Comments

@jgoz
Copy link

jgoz commented Oct 11, 2019

TypeScript Version: 3.7.x-dev.20191011

Search Terms: "Cannot read property 'parent' of undefined"

Code (JavaScript)

/**
 * @class
 */
function MyClass() {}

/**
 * @returns {new () => MyClass}
 */
export function createSpecialMyClass() {
  var f = function() {
    return new MyClass();
  };

  f.prototype.a = "a";

  return f;
}

tsconfig.json:

{
    "compilerOptions": {
        "allowJs": true,
        "declaration": true,
        "rootDir": "src",
        "outDir": "dist"
    },
    "include": ["src"]
}

Expected behavior:

Compiles and emits .js + .d.ts.

Actual behavior:

Error:

TypeError: Cannot read property 'parent' of undefined
    at getOuterTypeParameters (/Users/johng/dev/typescript-allowjs-bug/node_modules/typescript/lib/tsc.js:32718:29)
    at getOuterTypeParametersOfClassOrInterface (/Users/johng/dev/typescript-allowjs-bug/node_modules/typescript/lib/tsc.js:32769:20)
    at getDeclaredTypeOfClassOrInterface (/Users/johng/dev/typescript-allowjs-bug/node_modules/typescript/lib/tsc.js:33003:43)
    at compareSignaturesRelated (/Users/johng/dev/typescript-allowjs-bug/node_modules/typescript/lib/tsc.js:37883:83)
    at signatureRelatedTo (/Users/johng/dev/typescript-allowjs-bug/node_modules/typescript/lib/tsc.js:39492:24)
    at signaturesRelatedTo (/Users/johng/dev/typescript-allowjs-bug/node_modules/typescript/lib/tsc.js:39455:30)
    at structuredTypeRelatedTo (/Users/johng/dev/typescript-allowjs-bug/node_modules/typescript/lib/tsc.js:39034:43)
    at recursiveTypeRelatedTo (/Users/johng/dev/typescript-allowjs-bug/node_modules/typescript/lib/tsc.js:38783:53)
    at isRelatedTo (/Users/johng/dev/typescript-allowjs-bug/node_modules/typescript/lib/tsc.js:38405:38)
    at checkTypeRelatedTo (/Users/johng/dev/typescript-allowjs-bug/node_modules/typescript/lib/tsc.js:38089:26)

Playground Link:

Unable to figure out how to create a playground link with declaration: true.

Related Issues:

#33735 maybe? This one was blocking me previously.

@sandersn
Copy link
Member

Smaller repro:

var f = function() {
    return 12;
};

f.prototype.a = "a";

/** @type {new () => number } */
var x = f;

Still crashes on master.

@sandersn sandersn self-assigned this Oct 25, 2019
@sandersn sandersn added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Oct 25, 2019
@sandersn sandersn added this to the TypeScript 3.7.2 milestone Oct 25, 2019
sandersn added a commit that referenced this issue Oct 28, 2019
The constructor function code path in the return type checking of
signatures needs to pass the *merged* symbol of the declaration to
getDeclaredTypeOfClassOrInterface. Other callers of
getDeclaredTypeOfClassOrInterface do this, or used an already-merged
symbol.

Fixes #33993
@sandersn sandersn added the Fix Available A PR has been opened for this issue label Oct 28, 2019
sandersn added a commit that referenced this issue Oct 28, 2019
The constructor function code path in the return type checking of
signatures needs to pass the *merged* symbol of the declaration to
getDeclaredTypeOfClassOrInterface. Other callers of
getDeclaredTypeOfClassOrInterface do this, or used an already-merged
symbol.

Fixes #33993
typescript-bot pushed a commit to typescript-bot/TypeScript that referenced this issue Oct 28, 2019
Component commits:
ab9bc3a Fix type reference to merged prototype property assignment
The constructor function code path in the return type checking of
signatures needs to pass the *merged* symbol of the declaration to
getDeclaredTypeOfClassOrInterface. Other callers of
getDeclaredTypeOfClassOrInterface do this, or used an already-merged
symbol.

Fixes microsoft#33993
sandersn pushed a commit that referenced this issue Oct 28, 2019
Component commits:
ab9bc3a Fix type reference to merged prototype property assignment
The constructor function code path in the return type checking of
signatures needs to pass the *merged* symbol of the declaration to
getDeclaredTypeOfClassOrInterface. Other callers of
getDeclaredTypeOfClassOrInterface do this, or used an already-merged
symbol.

Fixes #33993
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants