diff --git a/tests/baselines/reference/objectLiteralContextualTyping.js b/tests/baselines/reference/objectLiteralContextualTyping.js new file mode 100644 index 00000000000..ebe10686516 --- /dev/null +++ b/tests/baselines/reference/objectLiteralContextualTyping.js @@ -0,0 +1,29 @@ +//// [objectLiteralContextualTyping.ts] +// Test related to #1774 + +interface Item { + name: string; + description?: string; +} + +declare function foo(item: Item): string; +declare function foo(item: any): number; + +var x = foo({ name: "Sprocket" }); +var x: string; + +var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); +var y: string; + +var z = foo({ a: 10 }); +var z: number; + + +//// [objectLiteralContextualTyping.js] +// Test related to #1774 +var x = foo({ name: "Sprocket" }); +var x; +var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); +var y; +var z = foo({ a: 10 }); +var z; diff --git a/tests/baselines/reference/objectLiteralContextualTyping.types b/tests/baselines/reference/objectLiteralContextualTyping.types new file mode 100644 index 00000000000..ff571ee541f --- /dev/null +++ b/tests/baselines/reference/objectLiteralContextualTyping.types @@ -0,0 +1,53 @@ +=== tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts === +// Test related to #1774 + +interface Item { +>Item : Item + + name: string; +>name : string + + description?: string; +>description : string +} + +declare function foo(item: Item): string; +>foo : { (item: Item): string; (item: any): number; } +>item : Item +>Item : Item + +declare function foo(item: any): number; +>foo : { (item: Item): string; (item: any): number; } +>item : any + +var x = foo({ name: "Sprocket" }); +>x : string +>foo({ name: "Sprocket" }) : string +>foo : { (item: Item): string; (item: any): number; } +>{ name: "Sprocket" } : { name: string; description?: string; } +>name : string + +var x: string; +>x : string + +var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); +>y : string +>foo({ name: "Sprocket", description: "Bumpy wheel" }) : string +>foo : { (item: Item): string; (item: any): number; } +>{ name: "Sprocket", description: "Bumpy wheel" } : { name: string; description: string; } +>name : string +>description : string + +var y: string; +>y : string + +var z = foo({ a: 10 }); +>z : number +>foo({ a: 10 }) : number +>foo : { (item: Item): string; (item: any): number; } +>{ a: 10 } : { a: number; } +>a : number + +var z: number; +>z : number + diff --git a/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts new file mode 100644 index 00000000000..5920066aaa6 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts @@ -0,0 +1,18 @@ +// Test related to #1774 + +interface Item { + name: string; + description?: string; +} + +declare function foo(item: Item): string; +declare function foo(item: any): number; + +var x = foo({ name: "Sprocket" }); +var x: string; + +var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); +var y: string; + +var z = foo({ a: 10 }); +var z: number;