Skip to content
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

Variables declared in array destructuring patterns can't be used in initializers of other variables in the same pattern #33257

Closed
thorn0 opened this issue Sep 5, 2019 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros
Milestone

Comments

@thorn0
Copy link

thorn0 commented Sep 5, 2019

TypeScript Version: 3.6.2

Search Terms: circular reference, array destructuring initializer

Code

// @strict
declare const x: number | undefined;
const [a, b = a] = [10, x];

Expected behavior: Should compile. Both a and b are of type number.

Actual behavior:
Error: 'a' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Playground Link: playground

Related Issues: #32950, #33191

@sandersn
Copy link
Member

sandersn commented Sep 6, 2019

Pretty sure this is a design limitation of the way that Typescript checks types. It uses a simple strategy augmented by contextual typing, but that is simple too, and happens at the same time during checking every time.

Still, it might be possible to tweak the order of checking in destructuring declarations to avoid the error.

@sandersn sandersn added the Bug A bug in TypeScript label Sep 6, 2019
@sandersn sandersn added this to the Backlog milestone Sep 6, 2019
@typescript-bot typescript-bot added the Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros label May 23, 2024
@typescript-bot
Copy link
Collaborator

👋 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 @thorn0

👍 Compiled

Historical Information
Version Reproduction Outputs
5.4.2

👍 Compiled

5.0.2, 5.1.3, 5.2.2, 5.3.2

❌ Failed: -

  • 'a' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

@thorn0 thorn0 closed this as completed May 24, 2024
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

4 participants