TypeScript/tests/baselines/reference/objectLiteralContextualTyping.types

91 lines
2.3 KiB
Plaintext
Raw Normal View History

2015-01-22 23:52:15 +01:00
=== tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts ===
// In a contextually typed object literal, each property value expression is contextually typed by
// the type of the property with a matching name in the contextual type, if any, or otherwise
// for a numerically named property, the numeric index type of the contextual type, if any, or otherwise
// the string index type of the contextual type, if any.
2015-01-22 23:52:15 +01:00
interface Item {
>Item : Item
2015-01-22 23:52:15 +01:00
name: string;
>name : string
2015-01-22 23:52:15 +01:00
description?: string;
>description : string
2015-01-22 23:52:15 +01:00
}
declare function foo(item: Item): string;
>foo : { (item: Item): string; (item: any): number; }
>item : Item
>Item : Item
2015-01-22 23:52:15 +01:00
declare function foo(item: any): number;
>foo : { (item: Item): string; (item: any): number; }
>item : any
2015-01-22 23:52:15 +01:00
var x = foo({ name: "Sprocket" });
>x : string
2015-01-22 23:52:15 +01:00
>foo({ name: "Sprocket" }) : string
>foo : { (item: Item): string; (item: any): number; }
2015-01-24 17:04:23 +01:00
>{ name: "Sprocket" } : { name: string; }
>name : string
2015-04-13 21:36:11 +02:00
>"Sprocket" : string
2015-01-22 23:52:15 +01:00
var x: string;
>x : string
2015-01-22 23:52:15 +01:00
var y = foo({ name: "Sprocket", description: "Bumpy wheel" });
>y : string
2015-01-22 23:52:15 +01:00
>foo({ name: "Sprocket", description: "Bumpy wheel" }) : string
>foo : { (item: Item): string; (item: any): number; }
2015-01-22 23:52:15 +01:00
>{ name: "Sprocket", description: "Bumpy wheel" } : { name: string; description: string; }
>name : string
2015-04-13 21:36:11 +02:00
>"Sprocket" : string
>description : string
2015-04-13 21:36:11 +02:00
>"Bumpy wheel" : string
2015-01-22 23:52:15 +01:00
var y: string;
>y : string
2015-01-22 23:52:15 +01:00
2015-01-23 00:12:55 +01:00
var z = foo({ name: "Sprocket", description: false });
>z : number
2015-01-23 00:12:55 +01:00
>foo({ name: "Sprocket", description: false }) : number
>foo : { (item: Item): string; (item: any): number; }
2015-01-23 00:12:55 +01:00
>{ name: "Sprocket", description: false } : { name: string; description: boolean; }
>name : string
2015-04-13 21:36:11 +02:00
>"Sprocket" : string
>description : boolean
2015-04-13 21:36:11 +02:00
>false : boolean
2015-01-23 00:12:55 +01:00
var z: number;
>z : number
2015-01-23 00:12:55 +01:00
var w = foo({ a: 10 });
>w : number
2015-01-22 23:52:15 +01:00
>foo({ a: 10 }) : number
>foo : { (item: Item): string; (item: any): number; }
2015-01-22 23:52:15 +01:00
>{ a: 10 } : { a: number; }
>a : number
2015-04-13 21:36:11 +02:00
>10 : number
2015-01-22 23:52:15 +01:00
2015-01-23 00:12:55 +01:00
var w: number;
>w : number
2015-01-23 00:12:55 +01:00
declare function bar<T>(param: { x?: T }): T;
>bar : <T>(param: { x?: T; }) => T
>T : T
>param : { x?: T; }
>x : T
>T : T
>T : T
2015-01-23 00:12:55 +01:00
var b = bar({});
>b : {}
2015-01-23 00:12:55 +01:00
>bar({}) : {}
>bar : <T>(param: { x?: T; }) => T
2015-01-24 17:04:23 +01:00
>{} : {}
2015-01-23 00:12:55 +01:00
var b: {};
>b : {}
2015-01-22 23:52:15 +01:00