We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
declaration, widened, d.ts, destructuring
https://www.typescriptlang.org/play?jsx=0&module=1&ts=5.1.6#code/GYVwdgxgLglg9mABMOcAUBKAXIg3gTxwEYBfPAKESsQCcBTKEGpXRQxIxE878ugDwAOcGlEQQEAZzGt8iALyIADFwXJUmANxA
function foo(): {y: 1} { return { y: 1 } } export const { y = 0 } = foo();
y is number in d.ts files, although the language service says y is 1|0
y
number
d.ts
1|0
y is 1|0 in d.ts files.
Without the = 0 assignment y properly becomes type 1 in d.ts
= 0
1
The text was updated successfully, but these errors were encountered:
Workaround: 0 as const.
0 as const
Sorry, something went wrong.
@Andarist I found a very similar issue. In the code below x is typed in ts as 0 | 1, but is typed as number in declarations.
x
0 | 1
export const x = Math.random() ? 1 : 0 // 0 | 1
Playground
Will your fix work for this example as well ?
Yes, I think so - what Jake commented on here is basically the same as your case above: https://github.com/microsoft/TypeScript/pull/55445/files#r1300377161
@Andarist Oh. Yeah. Forgot about that. Thanks π
Successfully merging a pull request may close this issue.
π Search Terms
declaration, widened, d.ts, destructuring
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?jsx=0&module=1&ts=5.1.6#code/GYVwdgxgLglg9mABMOcAUBKAXIg3gTxwEYBfPAKESsQCcBTKEGpXRQxIxE878ugDwAOcGlEQQEAZzGt8iALyIADFwXJUmANxA
π» Code
π Actual behavior
y
isnumber
ind.ts
files, although the language service saysy
is1|0
π Expected behavior
y
is1|0
ind.ts
files.Additional information about the issue
Without the
= 0
assignmenty
properly becomes type1
in d.tsThe text was updated successfully, but these errors were encountered: