-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 2.1.1 & rc
Sorry if this has already been reported. I searched around and couldn't find exactly this.
This is sort of difficult to describe, so here's an example:
interface Foo {
bar?: any;
baz?: any;
}
function foobar({ bar = {}, ...opts }: Foo = {}) {
console.log(bar);
console.log(opts.baz);
}
foobar(); // Throws error
foobar({ baz: 'hello' }); // No error
foobar({ bar: { greeting: 'hello' } }); // No errorExpected behavior:
I'd expect bar to still be initialized and available in the function call as an empty object when no args are given to the function.
Actual behavior:
The following error gets thrown (reproducible in the playground example above).
Uncaught TypeError: Cannot read property 'bar' of undefined
at foobar (<anonymous>:11:16)
at <anonymous>:16:1
at HTMLButtonElement.excuteButton.onclick (http://www.typescriptlang.org/play/playground.js:242)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue