ARTICLE AD BOX
First, playground
Then, code
type ListItem = { a: string b: number } //type Props = ListItem[] | ListItem[][] type Props = Array<ListItem> | Array<Array<ListItem>> function test (param: Props) { if('a' in param[0]) { const item: ListItem = param[0] } const firstItemOperator: ListItem | Array<ListItem> = param[0] const firstItemAt: ListItem | Array<ListItem> | undefined = param.at(0) if(Array.isArray(param[0])) { const item: ListItem[] = param[0] } if(Array.isArray(param.at(0))) { // Why error here? const item: ListItem[] = param.at(0) } }Finally, question
Why type narrowing is working with [] operator, and not with at() function?
There are related topics
https://github.com/microsoft/TypeScript/issues/53395 It seems in an issue with ReadonlyArray, which I explicitly removed for testingOtherwise, I don't understand the difference. I have a workaround, but I really need to know why it's not working as I expect.
