Skip to content

Function involving FlatArray is transformed in declaration in an incompatible type.Β #49572

@Lucas-Mercier-tech

Description

@Lucas-Mercier-tech

Bug Report

πŸ”Ž Search Terms

FlatArray declaration unknown

πŸ•— Version & Regression Information

  • This changed between versions 4.7.0-dev.20220406 and 4.7.0-dev.20220408 (still present in 4.7.3)

⏯ Playground Link

Playground link with relevant code (target: es2019)

πŸ’» Code

// This function's type is changed on declaration
export const fun = (
	subFun: <Collection, Field extends keyof Collection>()
		=> FlatArray<Collection[Field], 0>[]) => { };

// This argument should match the type of argument used by fun
const subFunExample = <Collection, Field extends keyof Collection>()
		: FlatArray<Collection[Field], 0>[] => [];

// Typescript does not throw any error there
fun(subFunExample);

// This is the type found for fun in the declaration file. It should be equivalent to the type for fun.
const fun_declaration: (subFun: <Collection, Field extends keyof Collection>() => (Collection[Field] extends infer T ? T extends Collection[Field] ? T extends readonly unknown[] ? unknown : T : never : never)[]) => void 
	= (_) => {};

// Typescript throws an error there.
fun_declaration(subFunExample);

πŸ™ Actual behavior

When the declaration is created, the type of fun is transformed to (subFun: <Collection, Field extends keyof Collection>() => (Collection[Field] extends infer T ? T extends Collection[Field] ? T extends readonly unknown[] ? unknown : T : never : never)[]) => void;.

This declaration type does not recognize arguments that were matched by the original type.

πŸ™‚ Expected behavior

No error. Declaration type should be equivalent to the original type: if typescript does not raise an error with the original type, it should raise an error for the declaration type.

I've tried to find a simpler type exhibiting this behavior, but didn't find any.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions