Skip to content

Compile error if I named last array destructuring element. #41548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
heroboy opened this issue Nov 16, 2020 · 3 comments
Open

Compile error if I named last array destructuring element. #41548

heroboy opened this issue Nov 16, 2020 · 3 comments
Labels
Bug A bug in TypeScript Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros
Milestone

Comments

@heroboy
Copy link

heroboy commented Nov 16, 2020

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 RyanCavanaugh added the Bug A bug in TypeScript label Nov 16, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Nov 16, 2020
@typescript-bot typescript-bot added the Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros label Nov 19, 2020
@theGreen233
Copy link

Hello, we are a group of researchers developing machine learning techniques to locate issues suitable for newcomers, and our model consider this issue as likely a "good first issue". May we recommend you to label it as "good first issue" so newcomers know where to choose?

Thank you!

@andrewbranch
Copy link
Member

This is not a good first issue

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 13, 2022

👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in the issue body running against the nightly TypeScript.


Issue body code block by @heroboy

❌ Failed: -

  • Object literal may only specify known properties, and 'day' does not exist in type '{ dataType: "a" | "b"; }'.
  • Object literal may only specify known properties, and 'day' does not exist in type '{ dataType: "a" | "b"; }'.

Historical Information
Version Reproduction Outputs
4.2.2, 4.3.2, 4.4.2, 4.5.2, 4.6.2

❌ Failed: -

  • 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"; }'.
  • 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"; }'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros
Projects
None yet
Development

No branches or pull requests

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy