Skip to content

Array.isArray( ) with readonly [] #61381

@jonlepage

Description

@jonlepage

🔎 Search Terms

Array.isArray( )

🕗 Version & Regression Information

  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground

💻 Code

// from: ms-vscode.vscode-typescript-next-5.9.20250307\node_modules\typescript\lib\lib.es5.d.ts
interface ArrayConstructor {
    new (arrayLength?: number): any[];
    new <T>(arrayLength: number): T[];
    new <T>(...items: T[]): T[];
    (arrayLength?: number): any[];
    <T>(arrayLength: number): T[];
    <T>(...items: T[]): T[];
    isArray(arg: any): arg is readonly any[]; // <== fix the Array.isArray() ✅
    isArray(arg: any): arg is any[];
    readonly prototype: any[];
}

//ex: this will work fine now 
	public hasStatus( entityWithStates: EntityWith<C.StatesComponent>, status: STATUS | readonly STATUS[]  ) {
		const { statesMap } = entityWithStates.get( C.StatesComponent ).read;
		return Array.isArray( status ) ? status.some( ( _status ) => statesMap.has( _status ) ) : statesMap.has( status );
	}

🙁 Actual behavior

type became any[]
Image

🙂 Expected behavior

support readonly array when do a Array.isArray()

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions