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
TypeScript 4.9.4
Playground link with relevant code
function foo(id: string) { const record: Record<string, number | Array<number>> = {}; const arr = record[id]; if (Array.isArray(arr)) { // work arr.push(1); } if (Array.isArray(record[id])) { // doesn't work record[id].push(1); } }
If the record value is used directly is not narrowed down to an array.
The record value type should be narrowed.
The text was updated successfully, but these errors were encountered:
Duplicate of #10530. Type narrowing does not occur for indexed access forms e[k] where k is not a literal.
e[k]
k
Sorry, something went wrong.
In fact using record.id does work, I didn't notice it before. Closing since it is a duplicate. Thanks.
get Property 'length' does not exist on type
No branches or pull requests
Bug Report
π Search Terms
π Version & Regression Information
TypeScript 4.9.4
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
If the record value is used directly is not narrowed down to an array.
π Expected behavior
The record value type should be narrowed.
The text was updated successfully, but these errors were encountered: