Skip to content

TypeError in tsc when destructuring assignment from ES6 object literal syntax #38175

@metalogical

Description

@metalogical

TypeScript Version: 3.9.0-dev.20200424

Search Terms: UnhandledPromiseRejectionWarning

Code

test.js

function fn(obj, k, v) {
  // this breaks
  const { x } = { ...obj, [k]: v }
  // but this works:
  const x = { ...obj, [k]: v }
}

Run tsc --allowJs test.js

Expected behavior:

The output should be the following:

error TS5055: Cannot write file 'test.js' because it would overwrite input file.
  Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.


Found 1 error.

Actual behavior:

/Users/naman/dev/go/src/github.com/kiteco/kiteco/sidebar/node_modules/typescript/lib/tsc.js:82820
                throw e;
                ^

TypeError: Cannot read property 'name' of undefined
    at getObjectLiteralIndexInfo (/Users/naman/dev/go/src/github.com/kiteco/kiteco/sidebar/node_modules/typescript/lib/tsc.js:46718:77)
    at createObjectLiteralType (/Users/naman/dev/go/src/github.com/kiteco/kiteco/sidebar/node_modules/typescript/lib/tsc.js:46887:67)
    at checkObjectLiteral (/Users/naman/dev/go/src/github.com/kiteco/kiteco/sidebar/node_modules/typescript/lib/tsc.js:46876:52)
    at checkExpressionWorker (/Users/naman/dev/go/src/github.com/kiteco/kiteco/sidebar/node_modules/typescript/lib/tsc.js:51490:28)
    at checkExpression (/Users/naman/dev/go/src/github.com/kiteco/kiteco/sidebar/node_modules/typescript/lib/tsc.js:51419:38)
    at checkExpressionCached (/Users/naman/dev/go/src/github.com/kiteco/kiteco/sidebar/node_modules/typescript/lib/tsc.js:51145:38)
    at checkDeclarationInitializer (/Users/naman/dev/go/src/github.com/kiteco/kiteco/sidebar/node_modules/typescript/lib/tsc.js:51158:114)
    at getTypeForVariableLikeDeclaration (/Users/naman/dev/go/src/github.com/kiteco/kiteco/sidebar/node_modules/typescript/lib/tsc.js:34194:74)
    at getTypeForBindingElementParent (/Users/naman/dev/go/src/github.com/kiteco/kiteco/sidebar/node_modules/typescript/lib/tsc.js:33966:61)
    at checkVariableLikeDeclaration (/Users/naman/dev/go/src/github.com/kiteco/kiteco/sidebar/node_modules/typescript/lib/tsc.js:53361:34)

Playground Link: I can't figure out how to make this happen in the playground

Related Issues: nope

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions