Closed
Description
TypeScript Version: 3.7.2 & 3.8.0-dev.20191128
Search Terms:
destructuring default value function
Code
interface ReturnVal {
something(a: string): string // has one param
}
function getFn(): ReturnVal {
return {
something(a) { return a }
}
}
interface PartialOptions {
something?(a: string, b?: string): string // has two params
}
function run(options: PartialOptions) {
const { something = getFn().something } = options;
const something2 = options.something ?? getFn().something;
return {
method() {
something('', '') // this should not error
something2('', '') // also wrong?
// and now the twist: hovering "something" and something2 (above) shows *correct* signatures. :)
}
}
}
Expected behavior:
Pick up the function signature of PartialOptions when checking the call.
Actual behavior:
Hover shows correct signature. Type check breaks saying single parameter is expected.
Related Issues:
found many issues about destructuring, but couldn't identify an issue about default values for functions. some are about generics behaviour, etc.