* Narrow type variables with union constraints when merited by contextual type * Narrow generics with union type constraints as indicated by contextual type * Accept new baselines * Add tests * Fix circularity for JSX elements * Remove unnecessary isConstraintPosition information from flow cache key * Update comment * Add additional tests * Rename to getNarrowableTypeForReference, remove getConstraintForLocation * Add comment * Fix removal of undefined in destructurings with initializers * Use getContextFreeTypeOfExpression in discriminateContextualTypeByObjectMembers * In obj[x], use constraint of obj's type only when x's type is non-generic * Add comment
37 lines
868 B
Plaintext
37 lines
868 B
Plaintext
=== tests/cases/compiler/nonNullParameterExtendingStringAssignableToString.ts ===
|
|
declare function foo(p: string): void;
|
|
>foo : (p: string) => void
|
|
>p : string
|
|
|
|
function fn<T extends string | undefined, U extends string>(one: T, two: U) {
|
|
>fn : <T extends string | undefined, U extends string>(one: T, two: U) => void
|
|
>one : T
|
|
>two : U
|
|
|
|
let three = Boolean() ? one : two;
|
|
>three : T | U
|
|
>Boolean() ? one : two : T | U
|
|
>Boolean() : boolean
|
|
>Boolean : BooleanConstructor
|
|
>one : T
|
|
>two : U
|
|
|
|
foo(one!);
|
|
>foo(one!) : void
|
|
>foo : (p: string) => void
|
|
>one! : string
|
|
>one : string | undefined
|
|
|
|
foo(two!);
|
|
>foo(two!) : void
|
|
>foo : (p: string) => void
|
|
>two! : NonNullable<U>
|
|
>two : U
|
|
|
|
foo(three!); // this line is the important one
|
|
>foo(three!) : void
|
|
>foo : (p: string) => void
|
|
>three! : string
|
|
>three : string | undefined
|
|
}
|