Skip to content

Stack overflow with recursive mapped types #19951

Closed
@falsandtru

Description

@falsandtru

From https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/lodash

cc @sandersn @ahejlsberg

TypeScript Version: master

Code

type PartialDeep<T> = {
    [P in keyof T]?: PartialDeep<T[P]>;
};
interface Struct {
    a: number;
    b: string;
    c: boolean;
}

declare function f<T>(): PartialDeep<T>;
var result: Partial<Struct> = f();

Expected behavior:

pass

Actual behavior:

$ node built/local/tsc.js index.ts
...\TypeScript\built\local\tsc.js:73240
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at ...\TypeScript\built\local\tsc.js:31397:29
    at Object.map (...\TypeScript\built\local\tsc.js:1703:29)
    at getAnonymousTypeInstantiation (...\TypeScript\built\local\tsc.js:31498:40)
    at instantiateType (...\TypeScript\built\local\tsc.js:31584:32)
    at getTemplateTypeFromMappedType (...\TypeScript\built\local\tsc.js:29217:21)
    at inferTypeForHomomorphicMappedType (...\TypeScript\built\local\tsc.js:33779:32)
    at inferFromObjectTypes (...\TypeScript\built\local\tsc.js:34031:48)
    at inferFromTypes (...\TypeScript\built\local\tsc.js:33985:29)
    at inferTypes (...\TypeScript\built\local\tsc.js:33824:13)
    at inferTargetType (...\TypeScript\built\local\tsc.js:33803:17)

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions