Skip to content

Destructured argument default value is not type checked #16970

@asfernandes

Description

@asfernandes

TypeScript Version: 2.4.1

Code

function test(n: number,
	{
		method = 'z'
	}: {
		method?: 'x' | 'y',
	} = {
		method: 'y'
	})
{
	console.log('test', n, method);
}

test(1);
test(2, {});

Expected behavior:

Compile error: z is not a possible value for method's type.

Actual behavior:

Prints:
test 1 y
test 2 z

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