Skip to content

4.1 and 4.2-dev fails on "TS7053: Element implicitly has an 'any' type" #41658

Closed
@grantila

Description

@grantila

TypeScript Version: 4.1.x and 4.2.0-dev.20201123
Works on 4.0.x

Search Terms: TS7053

Code

export type ComparablePrimitives = undefined | null | boolean | string | number;
export type ComparableArray = Array< Comparable >;
export type ComparableObject = { [ key: string ]: Comparable; };
export type Comparable =
	| ComparablePrimitives
	| ComparableArray
	| ComparableObject;

export function isEqual< T extends Comparable >( a: T, b: T ): boolean;
export function isEqual< T extends Comparable, U extends Comparable >( a: T, b: U ): false;
export function isEqual< T extends Comparable, U extends Comparable >( a: T, b: U ): boolean
{
	if ( Array.isArray( a ) && Array.isArray( b ) )
		return !a.some( ( value, index ) => !isEqual( value, b[ index ] ) );
	return false;
}

(the function body in this example is not my real code, but shows the compilation error)

Expected behavior: should compile

Actual behavior: fails with:

TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type '(undefined & (U extends readonly any[] ? unknown extends U ? never : readonly any[] : any[])) | (null & (U extends readonly any[] ? unknown extends U ? never : readonly any[] : any[])) | (string & (U extends readonly any[] ? unknown extends U ? never : readonly any[] : any[])) | ... 4 more ... | (ComparableObject & ...'.
  No index signature with a parameter of type 'number' was found on type '(undefined & (U extends readonly any[] ? unknown extends U ? never : readonly any[] : any[])) | (null & (U extends readonly any[] ? unknown extends U ? never : readonly any[] : any[])) | (string & (U extends readonly any[] ? unknown extends U ? never : readonly any[] : any[])) | ... 4 more ... | (ComparableObject & ...'.

  	return !a.some( ( value, index ) => !isEqual( value, b[ index ] ) );
  	                                                     ~~~~~~~~~~

Related Issues:

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