1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
=== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/optionalPropertyAssignableToStringIndexSignature.ts ===
declare let optionalProperties: { k1?: string };
>optionalProperties : { k1?: string | undefined; }
>k1 : string | undefined
declare let undefinedProperties: { k1: string | undefined };
>undefinedProperties : { k1: string | undefined; }
>k1 : string | undefined
declare let stringDictionary: { [key: string]: string };
>stringDictionary : { [key: string]: string; }
>key : string
stringDictionary = optionalProperties; // ok
>stringDictionary = optionalProperties : { k1?: string | undefined; }
>stringDictionary : { [key: string]: string; }
>optionalProperties : { k1?: string | undefined; }
stringDictionary = undefinedProperties; // error
>stringDictionary = undefinedProperties : { k1: string | undefined; }
>stringDictionary : { [key: string]: string; }
>undefinedProperties : { k1: string | undefined; }
declare let probablyArray: { [key: number]: string };
>probablyArray : { [key: number]: string; }
>key : number
declare let numberLiteralKeys: { 1?: string };
>numberLiteralKeys : { 1?: string | undefined; }
>1 : string | undefined
probablyArray = numberLiteralKeys; // error
>probablyArray = numberLiteralKeys : { 1?: string | undefined; }
>probablyArray : { [key: number]: string; }
>numberLiteralKeys : { 1?: string | undefined; }
declare let optionalUndefined: { k1?: undefined };
>optionalUndefined : { k1?: undefined; }
>k1 : undefined
let dict: { [key: string]: string } = optionalUndefined; // error
>dict : { [key: string]: string; }
>key : string
>optionalUndefined : { k1?: undefined; }
function f<T>() {
>f : <T>() => void
let optional: { k1?: T } = undefined!;
>optional : { k1?: T | undefined; }
>k1 : T | undefined
>undefined! : never
>undefined : undefined
let dict: { [key: string]: T | number } = optional; // ok
>dict : { [key: string]: number | T; }
>key : string
>optional : { k1?: T | undefined; }
}
|