Array.isArray type narrows to any[] for ReadonlyArray<T>
<!-- BUGS: Please use this template. --> <!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript --> <!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md --> **TypeScript Version:** 2.4.1 **Code** ```ts declare interface T { foo: string; } const immutable: T | ReadonlyArray<T> = []; if (Array.isArray(immutable)) { const x = immutable; // Any[] - Should be ReadonlyArray<T> } const mutable: T | Array<T> = []; if (Array.isArray(mutable)) { const x = mutable; // T[] } ``` **Expected behavior:** Should type narrow to ```ReadonlyArray<T>```, or at the very least ```T[]```. **Actual behavior:** Narrows to ```any[]```. Doesn't trigger warnings in noImplicitAny mode either.
Posted by jinder on Jul 7, 2017, 10:42 AM
Tags
Related issues
- Add 65536 size support for maps
- TypeScript 7.1 Iteration Plan
- nvim-treeconfig: upstream nvim-treesitter
- Add the "action" and "method" attributes to <button>
- [FEATURE] Support multiple Connector accounts (same connector, different accounts) in Claude and Claude Code on the web (claude.ai/code)
- > We were imposed GitHub for so many exercises!
Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments
support (Software)
Add 65536 size support for maps
TypeScript 7.1 Iteration Plan
nvim-treeconfig: upstream nvim-treesitter
Add the "action" and "method" attributes to <button>
[FEATURE] Support multiple Connector accounts (same connector, different accounts) in Claude and Claude Code on the web (claude.ai/code)
> We were imposed GitHub for so many exercises!
Add support for Visual Studio 2026 Integration
Support for Helm v4
Array.isArray type narrows to any[] for ReadonlyArray<T>
<!-- BUGS: Please use this template. --> <!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript --> <!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md --> **TypeScript Version:** 2.4.1 **Code** ```ts declare interface T { foo: string; } const immutable: T | ReadonlyArray<T> = []; if (Array.isArray(immutable)) { const x = immutable; // Any[] - Should be ReadonlyArray<T> } const mutable: T | Array<T> = []; if (Array.isArray(mutable)) { const x = mutable; // T[] } ``` **Expected behavior:** Should type narrow to ```ReadonlyArray<T>```, or at the very least ```T[]```. **Actual behavior:** Narrows to ```any[]```. Doesn't trigger warnings in noImplicitAny mode either.
Comments (0)
No comments yet. Start the discussion.