Skip to content

[Bug] Required in [K in keyof Required<T>] differ when using arrow function and normal function #53109

@jordan-boyer

Description

@jordan-boyer

Bug Report

🔎 Search Terms

  • required
  • arrow

🕗 Version & Regression Information

In typecript generated type (d.ts) they is an error while using Required in [K in keyof Required<T>] in a arrow function definition

  • This changed between versions 4.6.4 and newer version of typescript

⏯ Playground Link

https://www.typescriptlang.org/play?jsx=0&ts=4.6.4#code/KYDwDg9gTgLgBAYwgOwM7xsdAmOBeOAHgBV84AlYJKAE0PSgEtkBzAGjmWADdgoA+fgApUCABbAAtgEMAXHADeAKDiq4AbQDScZnADWwAJ4QAZhWABHAK6MowOsX4BdecS1OA3EoC+ASnz8iipqSGgQADbAAHThECwi4lLSvl7eSkqgkLBwJlbICDCMKHCY6ACMJGSU1HQMzOycPHyCCRIy8spqGtq6BsZmlNa29iTOru6p-p0hKKgR0bHxom3JqR5AA

💻 Code

export const test2 = <T = Record<string, never>>(schema: {
    [K in keyof Required<T>]: T[K];
}) => {
    console.log(schema);
}

export function test1<T = Record<string, never>>(schema: {
    [K in keyof Required<T>]: T[K];
}) {
    console.log(schema);
};

🙁 Actual behavior

In typescript 4.6.4 the d.ts file look like this:

export declare const test2: <T = Record<string, never>>(schema: { [K in keyof Required<T>]: T[K]; }) => void;
export declare function test1<T = Record<string, never>>(schema: {
    [K in keyof Required<T>]: T[K];
}): void;

And starting from 4.7 the d.ts file look like this:

export declare const test2: <T = Record<string, never>>(schema: Required<T> extends infer T_1 ? { [K in keyof T_1]: T[K]; } : never) => void;
export declare function test1<T = Record<string, never>>(schema: {
    [K in keyof Required<T>]: T[K];
}): void;

🙂 Expected behavior

This should be compiled to the same output as the 4.6 version

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions