Open
Description
TypeScript Version: v4.0.5
Search Terms: destructuring assignment , Object literal may only specify known properties
Code
declare function foo<T extends { dataType: 'a' | 'b'; }>(template: T): [T, any, any]; //<-- there no error, when it is [any,any,any]
declare function bar<T extends { dataType: 'a' | 'b'; }>(template: T): [T, any];
function test_foo() {
const [, ,] = foo({ dataType: 'a', day: 0 });
const [x, y, z] = foo({ dataType: 'a', day: 0 });
const [, , t] = foo({ dataType: 'a', day: 0 }); //<-- red line under the `day`
console.log(x, y, z, t);
}
function test_bar() {
const [,] = bar({ dataType: 'a', day: 0 });
const [x, y] = bar({ dataType: 'a', day: 0 });
const [, z] = bar({ dataType: 'a', day: 0 });//<-- red line under the `day`
console.log(x, y, z);
}
Expected behavior:
no compile error
Actual behavior:
Argument of type '{ dataType: "a"; day: number; }' is not assignable to parameter of type '{ dataType: "a" | "b"; }'. Object literal may only specify known properties, and 'day' does not exist in type '{ dataType: "a" | "b"; }'.
**Playground Link:
link
Related Issues: