-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosThis issue has compiler-backed repros: https://aka.ms/ts-repros
Milestone
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:
RyanCavanaugh and Copilot
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosThis issue has compiler-backed repros: https://aka.ms/ts-repros