frank-dspeed / frank-dspeed

Other
2 stars 0 forks source link

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

Open frank-dspeed opened 2 years ago

frank-dspeed commented 2 years ago

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