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

Crash when calling a JS function tagged @constructor but no properties #34346

Closed
brasten opened this issue Oct 14, 2019 · 3 comments · Fixed by #34575
Closed

Crash when calling a JS function tagged @constructor but no properties #34346

brasten opened this issue Oct 14, 2019 · 3 comments · Fixed by #34575
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@brasten
Copy link

brasten commented Oct 14, 2019

TypeScript Version: 3.7.0-dev.20191014

Search Terms:
Cannot read property 'parent' of undefined

Code

// src/Dependency.js
/**
 * Some dependency.
 *
 * @param {object} opts
 * @constructor
 */
function Dependency(opts) {
  // we're tagged as a constructor but obviously not used that way.
  return Object.assign({}, opts);
}

module.exports = Dependency;
// src/index.ts
const Dependency = require('./Dependency');
const deps = Dependency({});

GitHub repo:
https://github.com/brasten/ts-jsdoc-constructor-error

Expected behavior:
Successful compilation (as under previous versions)
OR
a compilation error/warning pointing to the issue (@constructor does not match up with usage in this case). It took a while to track down which files in my project were causing the issue, and then more time to figure out what the specific issue was.

Actual behavior:

> tsc -b

/Users/brasten/Projects/Scratch/BugReports/ts-top-level-jsdoc/node_modules/typescript/lib/tsc.js:78446
                throw e;
                ^

TypeError: Cannot read property 'parent' of undefined
    at getOuterTypeParameters (/Users/brasten/Projects/Scratch/BugReports/ts-top-level-jsdoc/node_modules/typescript/lib/tsc.js:32718:29)
    at getOuterTypeParametersOfClassOrInterface (/Users/brasten/Projects/Scratch/BugReports/ts-top-level-jsdoc/node_modules/typescript/lib/tsc.js:32769:20)
    at getDeclaredTypeOfClassOrInterface (/Users/brasten/Projects/Scratch/BugReports/ts-top-level-jsdoc/node_modules/typescript/lib/tsc.js:33003:43)
    at createAnonymousTypeNode (/Users/brasten/Projects/Scratch/BugReports/ts-top-level-jsdoc/node_modules/typescript/lib/tsc.js:29876:59)
    at typeToTypeNodeHelper (/Users/brasten/Projects/Scratch/BugReports/ts-top-level-jsdoc/node_modules/typescript/lib/tsc.js:29825:28)
    at /Users/brasten/Projects/Scratch/BugReports/ts-top-level-jsdoc/node_modules/typescript/lib/tsc.js:29617:106
    at withContext (/Users/brasten/Projects/Scratch/BugReports/ts-top-level-jsdoc/node_modules/typescript/lib/tsc.js:29661:37)
    at Object.typeToTypeNode (/Users/brasten/Projects/Scratch/BugReports/ts-top-level-jsdoc/node_modules/typescript/lib/tsc.js:29617:28)
    at typeToString (/Users/brasten/Projects/Scratch/BugReports/ts-top-level-jsdoc/node_modules/typescript/lib/tsc.js:29584:40)
    at resolveCallExpression (/Users/brasten/Projects/Scratch/BugReports/ts-top-level-jsdoc/node_modules/typescript/lib/tsc.js:46142:105)

Playground Link: None, not sure how to set up issue in Playground. See Github link above.

@Knagis
Copy link
Contributor

Knagis commented Oct 15, 2019

This same issue happens when using TS 3.7.0 to transpile BabylonJS es6 code.

    TypeError: node_modules/@babylonjs/core/Engines/Processors/shaderCodeCursor.js: Cannot read property 'parent' of undefined

      at getOuterTypeParameters (../../node_modules/typescript/lib/typescript.js:39622:29)
      at getOuterTypeParametersOfClassOrInterface (../../node_modules/typescript/lib/typescript.js:39675:20)
      at getDeclaredTypeOfClassOrInterface (../../node_modules/typescript/lib/typescript.js:39948:43)
      at createAnonymousTypeNode (../../node_modules/typescript/lib/typescript.js:36343:59)
      at typeToTypeNodeHelper (../../node_modules/typescript/lib/typescript.js:36289:28)
      at ../../node_modules/typescript/lib/typescript.js:36078:106
      at withContext (../../node_modules/typescript/lib/typescript.js:36123:37)
      at Object.typeToTypeNode (../../node_modules/typescript/lib/typescript.js:36078:28)
      at typeToString (../../node_modules/typescript/lib/typescript.js:36045:40)
      at reportNonexistentProperty (../../node_modules/typescript/lib/typescript.js:53822:165)

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Oct 17, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.7.1 milestone Oct 17, 2019
@sandersn
Copy link
Member

Smaller repro:

// @filename: dependency.js
/**
 * @constructor
 */
function Dependency(j) {
  return j
}
Dependency({})

@sandersn
Copy link
Member

The crash is in the error reporting code, which is why we didn't issue a nice error for the mismatch.

@sandersn sandersn added the Fix Available A PR has been opened for this issue label Oct 18, 2019
@sandersn sandersn changed the title "TypeError: Cannot read property 'parent' of undefined" with allowJs + @constructor + JS as source and referencing file Crash when calling a JS function tagged @constructor but no properties Oct 18, 2019
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
Development

Successfully merging a pull request may close this issue.

4 participants