Skip to content

Deep nested object type inference #34922

@eyal1990

Description

@eyal1990

TypeScript Version: 3.6.4

Search Terms: Deep nested object type inference

Code

export interface A {
	b: B[];
}

export interface B {
	c: C[];
}

export interface C {
	d: D[];
}

export interface D {
	e: E[];
}
export interface E {
	id?: string;
}

// Doesn't work as expected
export const a1: A[] = [
	{
		b: [
			{
				c: [
					{
						d: [
							{
								e: [{ f: 'f' }], // Doesn't show error on f: 'f'
							},
						],
					},
				],
			},
		],
	},
];

// Work as expected
export const a2: A = {
	b: [
		{
			c: [
				{
					d: [
						{
							e: [{ f: 'f' }], // Does show error on f: 'f'
						},
					],
				},
			],
		},
	],
};

Expected behavior: Show error for unknown property 'f'

Actual behavior: Doesn't show error for unknown property 'f'

Playground Link:
http://www.typescriptlang.org/play/?ts=3.7-Beta#code/KYDwDg9gTgLgBASwHY2FAZgQwMbDgQTgG8AoASACMAuOAIQG0BdAbhIF8STRJZEU0suOsXLYaAYSasOXcNHjJUGHHnEiyAExoARKe07d5fJYLzb1wGgFE9HQ70UCVcK+oQaA-DQDOMKMgBzaQM5XmwIJF84TABGGnwmOABeOHpyUjJKGjTMsgzcsVTyXLzikq0iktz8qrJLVKI4dBoAcnQWuDZGABoykrZe2p6+sgG+4dyxzImxlhCeeHDI+EwAJnjk9WpK0oLsvprMipyqw9z6+kbmuDaOrsGqqZKJyYeyF6nhtlYgA
Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions