Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9713,7 +9713,7 @@ func (c *Checker) inferTypeArguments(node *ast.Node, signature *Signature, args
outerReturnMapper = c.createOuterReturnMapper(outerContext)
}
returnSourceType := c.instantiateType(contextualType, outerReturnMapper)
c.inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType, InferencePriorityNone, false)
c.inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType, InferencePriorityReturnType, false)
if core.Some(returnContext.inferences, hasInferenceCandidates) {
context.returnMapper = c.getMapperFromContext(c.cloneInferredPartOfContext(returnContext))
} else {
Expand Down Expand Up @@ -31884,7 +31884,7 @@ func (c *Checker) instantiateContextualType(contextualType *Type, node *ast.Node
// the 'boolean' type from the contextual type such that contextually typed boolean
// literals actually end up widening to 'boolean' (see #48363).
t := c.instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper)
if t.flags&TypeFlagsAnyOrUnknown == 0 {
if t.flags&(TypeFlagsAnyOrUnknown|TypeFlagsNever) == 0 {
if t.flags&TypeFlagsUnion != 0 && containsType(t.Types(), c.regularFalseType) && containsType(t.Types(), c.regularTrueType) {
return c.filterType(t, func(t *Type) bool {
return t != c.regularFalseType && t != c.regularTrueType
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ declare function accept<Value extends Pattern<{ list: { prop: string }[] }>>(val
accept({
>accept({ list: array({ prop: when(value => { const text: string = value; return true; }), }),}) : void
>accept : <Value extends Pattern<{ list: { prop: string; }[]; }>>(value: Value) => void
>{ list: array({ prop: when(value => { const text: string = value; return true; }), }),} : { list: Matcher<{ prop: string; }[], { prop: Matcher<unknown, unknown>; }>; }
>{ list: array({ prop: when(value => { const text: string = value; return true; }), }),} : { list: Matcher<{ prop: string; }[], { prop: Matcher<string, unknown>; }>; }

list: array({
>list : Matcher<{ prop: string; }[], { prop: Matcher<unknown, unknown>; }>
>array({ prop: when(value => { const text: string = value; return true; }), }) : Matcher<{ prop: string; }[], { prop: Matcher<unknown, unknown>; }>
>list : Matcher<{ prop: string; }[], { prop: Matcher<string, unknown>; }>
>array({ prop: when(value => { const text: string = value; return true; }), }) : Matcher<{ prop: string; }[], { prop: Matcher<string, unknown>; }>
>array : <Input, Value extends Pattern<ArrayElement<Input>>>(value: Value) => Matcher<Input, Value>
>{ prop: when(value => { const text: string = value; return true; }), } : { prop: Matcher<unknown, unknown>; }
>{ prop: when(value => { const text: string = value; return true; }), } : { prop: Matcher<string, unknown>; }

prop: when(value => {
>prop : Matcher<unknown, unknown>
>when(value => { const text: string = value; return true; }) : Matcher<unknown, unknown>
>prop : Matcher<string, unknown>
>when(value => { const text: string = value; return true; }) : Matcher<string, unknown>
>when : <Input, Callback extends (value: Input) => unknown>(callback: Callback) => Matcher<Input>
>value => { const text: string = value; return true; } : (value: unknown) => boolean
>value : unknown
>value => { const text: string = value; return true; } : (value: string) => boolean
>value : string

const text: string = value;
>text : string
>value : unknown
>value : string

return true;
>true : true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//// [tests/cases/compiler/contextualReturnTypeInferenceUnions.ts] ////

=== contextualReturnTypeInferenceUnions.ts ===
// https://github.com/microsoft/TypeScript/issues/64690

type Ok<T> = { ok: true; value: T };
>Ok : Symbol(Ok, Decl(contextualReturnTypeInferenceUnions.ts, 0, 0))
>T : Symbol(T, Decl(contextualReturnTypeInferenceUnions.ts, 2, 8))
>ok : Symbol(ok, Decl(contextualReturnTypeInferenceUnions.ts, 2, 14))
>value : Symbol(value, Decl(contextualReturnTypeInferenceUnions.ts, 2, 24))
>T : Symbol(T, Decl(contextualReturnTypeInferenceUnions.ts, 2, 8))

type Err<E> = { ok: false; value: E };
>Err : Symbol(Err, Decl(contextualReturnTypeInferenceUnions.ts, 2, 36))
>E : Symbol(E, Decl(contextualReturnTypeInferenceUnions.ts, 3, 9))
>ok : Symbol(ok, Decl(contextualReturnTypeInferenceUnions.ts, 3, 15))
>value : Symbol(value, Decl(contextualReturnTypeInferenceUnions.ts, 3, 26))
>E : Symbol(E, Decl(contextualReturnTypeInferenceUnions.ts, 3, 9))

declare function ok<const T>(value: T): Ok<T>;
>ok : Symbol(ok, Decl(contextualReturnTypeInferenceUnions.ts, 3, 38))
>T : Symbol(T, Decl(contextualReturnTypeInferenceUnions.ts, 4, 20))
>value : Symbol(value, Decl(contextualReturnTypeInferenceUnions.ts, 4, 29))
>T : Symbol(T, Decl(contextualReturnTypeInferenceUnions.ts, 4, 20))
>Ok : Symbol(Ok, Decl(contextualReturnTypeInferenceUnions.ts, 0, 0))
>T : Symbol(T, Decl(contextualReturnTypeInferenceUnions.ts, 4, 20))

export function f(): Ok<string[]> | Err<string> {
>f : Symbol(f, Decl(contextualReturnTypeInferenceUnions.ts, 4, 46))
>Ok : Symbol(Ok, Decl(contextualReturnTypeInferenceUnions.ts, 0, 0))
>Err : Symbol(Err, Decl(contextualReturnTypeInferenceUnions.ts, 2, 36))

return ok([]);
>ok : Symbol(ok, Decl(contextualReturnTypeInferenceUnions.ts, 3, 38))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//// [tests/cases/compiler/contextualReturnTypeInferenceUnions.ts] ////

=== contextualReturnTypeInferenceUnions.ts ===
// https://github.com/microsoft/TypeScript/issues/64690

type Ok<T> = { ok: true; value: T };
>Ok : Ok<T>
>ok : true
>true : true
>value : T

type Err<E> = { ok: false; value: E };
>Err : Err<E>
>ok : false
>false : false
>value : E

declare function ok<const T>(value: T): Ok<T>;
>ok : <const T>(value: T) => Ok<T>
>value : T

export function f(): Ok<string[]> | Err<string> {
>f : () => Ok<string[]> | Err<string>

return ok([]);
>ok([]) : Ok<[]>
>ok : <const T>(value: T) => Ok<T>
>[] : []
}

Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ export const yun = unwrap(y);

// $ExpectType { kind: "a"; a: 3; }
export const yone = unwrap(sepsis({ low: 1, sign: { kind: 'a', a: 3 }}));
>yone : { kind: string; a: number; }
>unwrap(sepsis({ low: 1, sign: { kind: 'a', a: 3 }})) : { kind: string; a: number; }
>yone : { kind: "a"; a: 3; }
>unwrap(sepsis({ low: 1, sign: { kind: 'a', a: 3 }})) : { kind: "a"; a: 3; }
>unwrap : <T>(w: Wrapper<T>) => T
>sepsis({ low: 1, sign: { kind: 'a', a: 3 }}) : Wrapper<{ kind: string; a: number; }>
>sepsis({ low: 1, sign: { kind: 'a', a: 3 }}) : Wrapper<{ kind: "a"; a: 3; }>
>sepsis : <T extends Signs>(opts: Opts<T>) => Wrapper<T>
>{ low: 1, sign: { kind: 'a', a: 3 }} : { low: number; sign: { kind: string; a: number; }; }
>{ low: 1, sign: { kind: 'a', a: 3 }} : { low: number; sign: { kind: "a"; a: 3; }; }
>low : number
>1 : 1
>sign : { kind: string; a: number; }
>{ kind: 'a', a: 3 } : { kind: string; a: number; }
>kind : string
>sign : { kind: "a"; a: 3; }
>{ kind: 'a', a: 3 } : { kind: "a"; a: 3; }
>kind : "a"
>'a' : "a"
>a : number
>a : 3
>3 : 3

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @noEmit: true

// https://github.com/microsoft/TypeScript/issues/64690

type Ok<T> = { ok: true; value: T };
type Err<E> = { ok: false; value: E };
declare function ok<const T>(value: T): Ok<T>;

export function f(): Ok<string[]> | Err<string> {
return ok([]);
}
Loading