2014-08-15 23:33:16 +02:00
|
|
|
=== tests/cases/compiler/bestCommonTypeWithContextualTyping.ts ===
|
|
|
|
interface Contextual {
|
|
|
|
>Contextual : Contextual
|
|
|
|
|
|
|
|
dummy;
|
|
|
|
>dummy : any
|
|
|
|
|
|
|
|
p?: number;
|
|
|
|
>p : number
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Ellement {
|
|
|
|
>Ellement : Ellement
|
|
|
|
|
|
|
|
dummy;
|
|
|
|
>dummy : any
|
|
|
|
|
|
|
|
p: any;
|
|
|
|
>p : any
|
|
|
|
}
|
|
|
|
|
|
|
|
var e: Ellement;
|
|
|
|
>e : Ellement
|
|
|
|
>Ellement : Ellement
|
|
|
|
|
|
|
|
// All of these should pass. Neither type is a supertype of the other, but the RHS should
|
|
|
|
// always use Ellement in these examples (not Contextual). Because Ellement is assignable
|
|
|
|
// to Contextual, no errors.
|
|
|
|
var arr: Contextual[] = [e]; // Ellement[]
|
|
|
|
>arr : Contextual[]
|
|
|
|
>Contextual : Contextual
|
|
|
|
>[e] : Ellement[]
|
|
|
|
>e : Ellement
|
|
|
|
|
|
|
|
var obj: { [s: string]: Contextual } = { s: e }; // { s: Ellement; [s: string]: Ellement }
|
2014-12-06 01:58:49 +01:00
|
|
|
>obj : { [s: string]: Contextual; }
|
2014-08-15 23:33:16 +02:00
|
|
|
>s : string
|
|
|
|
>Contextual : Contextual
|
|
|
|
>{ s: e } : { [x: string]: Ellement; s: Ellement; }
|
|
|
|
>s : Ellement
|
2014-08-25 19:36:12 +02:00
|
|
|
>e : Ellement
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
var conditional: Contextual = null ? e : e; // Ellement
|
|
|
|
>conditional : Contextual
|
|
|
|
>Contextual : Contextual
|
|
|
|
>null ? e : e : Ellement
|
|
|
|
>e : Ellement
|
|
|
|
>e : Ellement
|
|
|
|
|
|
|
|
var contextualOr: Contextual = e || e; // Ellement
|
|
|
|
>contextualOr : Contextual
|
|
|
|
>Contextual : Contextual
|
|
|
|
>e || e : Ellement
|
|
|
|
>e : Ellement
|
|
|
|
>e : Ellement
|
|
|
|
|