Skip to content

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

Closed

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.

Activity

  1. weswigham commented on Jun 16, 2022

    @weswigham
    Member

    Hm, so our old emit was compatible, true, but it didn't execute over unions correctly. The new emit was introduced to distribute over unions correctly, but what I find most concerning is that unknown[] has appeared out of thin air. It used to be
    export declare const fun: (subFun: <Collection, Field extends keyof Collection>() => (Collection[Field] extends readonly (infer InnerArr)[] ? InnerArr : Collection[Field])[]) => void which was correctly generic, if not distributive, however the inner infer has suddenly evaporated now - that's definitely not right. I'm guessing something is being over-instantiated during construction of the new wrapper in this recursive type alias case.

  2. added
    BugA bug in TypeScript
    and removed
    Needs InvestigationThis issue needs a team member to investigate its status.
    on Jun 16, 2022
  3. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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