You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The const modifier does not behave as expected. Typescript would warn me to infer the const generic parameters when I use the spread argument in a function when the literal type object consists of 2 different primitive literals.
And I am not sure whether this type of behaviour is intentional.
This behaviour begins starting at typescript 5.0 (where the const modifier is introduced)
I have been seeing this behaviour between typescript 5.0 to the nightly build of 5.1
Typescript is inferring that the const U should be 3 instead of 3 | 4 | 5 | '6' | '7'
It prompts an error stating that Number 4 is not assignable to the parameter of type A | 3 for concatnatedArray.
While both perfectConcatenatedArray and okayConcatenatedArray are perfectly fine
🙂 Expected behaviour
I would expect concatnatedArray to have type 1 | '2' | 3 | 4 | 5 | '6' | '7'.
It is possible to do so if I wrote it in a class manner and chain the concat function. But I cannot do it within the same concat function.
Bug Report
The const modifier does not behave as expected. Typescript would warn me to infer the const generic parameters when I use the spread argument in a function when the literal type object consists of 2 different primitive literals.
And I am not sure whether this type of behaviour is intentional.
🔎 Search Terms
const modifier, typescript5, spread syntax, spread argument
🕗 Version & Regression Information
This behaviour begins starting at typescript 5.0 (where the const modifier is introduced)
I have been seeing this behaviour between typescript 5.0 to the nightly build of 5.1
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behaviour
Typescript is inferring that the
const U
should be3
instead of3 | 4 | 5 | '6' | '7'
It prompts an error stating that
Number 4
is not assignable to the parameter of typeA | 3
forconcatnatedArray
.While both
perfectConcatenatedArray
andokayConcatenatedArray
are perfectly fine🙂 Expected behaviour
I would expect concatnatedArray to have type
1 | '2' | 3 | 4 | 5 | '6' | '7'
.It is possible to do so if I wrote it in a class manner and chain the concat function. But I cannot do it within the same concat function.
Playground link to the class version of the issue
The text was updated successfully, but these errors were encountered: