-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Support for as const
in Javascript
#35821
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
Comments
What does that mean?? You want something in the type system that compiles to (JS) CODE? Because otherwise that request is impossible, since the types are completely gone at that point. If this is what you want, you won't get it — there is no way a request to create JS code for a type annotation will be accepted (and that's good). Apart from that, what is wrong with
This is exactly what these two mentioned options already provide. I cannot imagine I'm alone saying that I don't understand what you want exactly. The use case is very unspecific too. It does sound like you are confused about "types" in TS vs JS. Your last example under "Javascript" lists a Typescript type! Where would that come from?? |
This means having typing information the
Readonly array is in the code examples as it is needed to support Without the In Typescript, this is achievable by casting the literal, but javascript supports no such option (which is the problem). The Hope that clarifies the desired goal. |
as const
in Javascript
as const
in Javascriptas const
in Javascript Typechecker
as const
in Javascript Typecheckeras const
in Javascript
So you want to annotate |
That looks to be exactly the right issue. Will close in lieu of #30680. |
Search Terms
const array, javascript, as const
Suggestion
The
as const
feature allows for treating literal arrays as tuples, and is useful for API design. I'd like to be able to leverage this from javascript when consuming a typescript package.Seeing as the user cannot denote
as const
for arrays in javascript itself, I was hoping there could be a path to define a function parameter as a const array. This would only work if passing in an array literal, but for API design could be extremely powerful.It would also be useful to convey the intent that a parameter supports a const array as well.
Use Cases
Primary use case for this, will be for API designers, to allow for more expressive typings.
Examples
Field Extraction
Typescript
Javascript
CSV Object Creation
Typescript
Javascript
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: