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

proposal-typescript allow driving const values or driving type values #10

Open
frank-dspeed opened this issue May 21, 2022 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@frank-dspeed
Copy link
Owner

frank-dspeed commented May 21, 2022

typescript

const numberArray = [1,2]; // or JSON any Object
const literalArray = numberArray as const // declare const literalArray: readonly [1, 2];

js

const numberArray = [1,2]; // or JSON any Object
const literalArray = /** @type {const} */ (numberArray) // declare const literalArray: readonly [1, 2];

the above does not work but should work: https://www.typescriptlang.org/play?target=99&jsx=0&ts=4.7.0-beta&filetype=js#code/MYewdgzgLgBGCuBbARgUwE4EF3oIYE8YBeGAbQEYAaAJgF0BuAKFElgBsBLKDXN7PQiQD0AKhEwAAlHwAHVDADeLaAF8YIoTAAUFGrQCUQA

const numberArray = [1,2];
const literalArray = /** @type {const} */ (numberArray) // declare const literalArray: number[]; should be readonly [1, 2]; when this would be supported.

it got implemented in a way so that you need to indicate that on assignment hope that helps

closes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant