Skip to content
New issue

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

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

Closed
grantila opened this issue Nov 23, 2020 · 4 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@grantila
Copy link

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:

@DanielRosenwasser
Copy link
Member

Are you using noUncheckedIndexedAccess?

@grantila
Copy link
Author

@DanielRosenwasser no, I just tried it, and I get quite a few new errors in other parts of the codebase, but this one error is not affected, it's still there, without noUncheckedIndexedAccess specified, or with it explicitly true or false.

@RyanCavanaugh
Copy link
Member

This is another isArray fallout; ref #39258

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Dec 3, 2020
@RyanCavanaugh
Copy link
Member

Evaluating isArray breaks at #41808

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants