-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33252 from microsoft/fix33131
Make lower priority inference when source is completely matched in target
- Loading branch information
Showing
7 changed files
with
215 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//// [observableInferenceCanBeMade.ts] | ||
// Repro from #33131 | ||
|
||
declare function of<T>(a: T): Observable<T>; | ||
declare function from<O extends ObservableInput<any>>(input: O): Observable<ObservedValueOf<O>>; | ||
|
||
type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never; | ||
|
||
interface Subscribable<T> { | ||
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void; | ||
} | ||
type ObservableInput<T> = Subscribable<T> | Subscribable<never>; | ||
|
||
|
||
declare class Observable<T> implements Subscribable<T> { | ||
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void; | ||
} | ||
|
||
function asObservable(input: string | ObservableInput<string>): Observable<string> { | ||
return typeof input === 'string' ? of(input) : from(input) | ||
} | ||
|
||
|
||
//// [observableInferenceCanBeMade.js] | ||
"use strict"; | ||
// Repro from #33131 | ||
function asObservable(input) { | ||
return typeof input === 'string' ? of(input) : from(input); | ||
} |
80 changes: 80 additions & 0 deletions
80
tests/baselines/reference/observableInferenceCanBeMade.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
=== tests/cases/compiler/observableInferenceCanBeMade.ts === | ||
// Repro from #33131 | ||
|
||
declare function of<T>(a: T): Observable<T>; | ||
>of : Symbol(of, Decl(observableInferenceCanBeMade.ts, 0, 0)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 2, 20)) | ||
>a : Symbol(a, Decl(observableInferenceCanBeMade.ts, 2, 23)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 2, 20)) | ||
>Observable : Symbol(Observable, Decl(observableInferenceCanBeMade.ts, 10, 64)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 2, 20)) | ||
|
||
declare function from<O extends ObservableInput<any>>(input: O): Observable<ObservedValueOf<O>>; | ||
>from : Symbol(from, Decl(observableInferenceCanBeMade.ts, 2, 44)) | ||
>O : Symbol(O, Decl(observableInferenceCanBeMade.ts, 3, 22)) | ||
>ObservableInput : Symbol(ObservableInput, Decl(observableInferenceCanBeMade.ts, 9, 1)) | ||
>input : Symbol(input, Decl(observableInferenceCanBeMade.ts, 3, 54)) | ||
>O : Symbol(O, Decl(observableInferenceCanBeMade.ts, 3, 22)) | ||
>Observable : Symbol(Observable, Decl(observableInferenceCanBeMade.ts, 10, 64)) | ||
>ObservedValueOf : Symbol(ObservedValueOf, Decl(observableInferenceCanBeMade.ts, 3, 96)) | ||
>O : Symbol(O, Decl(observableInferenceCanBeMade.ts, 3, 22)) | ||
|
||
type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never; | ||
>ObservedValueOf : Symbol(ObservedValueOf, Decl(observableInferenceCanBeMade.ts, 3, 96)) | ||
>O : Symbol(O, Decl(observableInferenceCanBeMade.ts, 5, 21)) | ||
>O : Symbol(O, Decl(observableInferenceCanBeMade.ts, 5, 21)) | ||
>ObservableInput : Symbol(ObservableInput, Decl(observableInferenceCanBeMade.ts, 9, 1)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 5, 57)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 5, 57)) | ||
|
||
interface Subscribable<T> { | ||
>Subscribable : Symbol(Subscribable, Decl(observableInferenceCanBeMade.ts, 5, 73)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 7, 23)) | ||
|
||
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void; | ||
>subscribe : Symbol(Subscribable.subscribe, Decl(observableInferenceCanBeMade.ts, 7, 27)) | ||
>next : Symbol(next, Decl(observableInferenceCanBeMade.ts, 8, 14)) | ||
>value : Symbol(value, Decl(observableInferenceCanBeMade.ts, 8, 22)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 7, 23)) | ||
>error : Symbol(error, Decl(observableInferenceCanBeMade.ts, 8, 40)) | ||
>error : Symbol(error, Decl(observableInferenceCanBeMade.ts, 8, 50)) | ||
>complete : Symbol(complete, Decl(observableInferenceCanBeMade.ts, 8, 70)) | ||
} | ||
type ObservableInput<T> = Subscribable<T> | Subscribable<never>; | ||
>ObservableInput : Symbol(ObservableInput, Decl(observableInferenceCanBeMade.ts, 9, 1)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 10, 21)) | ||
>Subscribable : Symbol(Subscribable, Decl(observableInferenceCanBeMade.ts, 5, 73)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 10, 21)) | ||
>Subscribable : Symbol(Subscribable, Decl(observableInferenceCanBeMade.ts, 5, 73)) | ||
|
||
|
||
declare class Observable<T> implements Subscribable<T> { | ||
>Observable : Symbol(Observable, Decl(observableInferenceCanBeMade.ts, 10, 64)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 13, 25)) | ||
>Subscribable : Symbol(Subscribable, Decl(observableInferenceCanBeMade.ts, 5, 73)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 13, 25)) | ||
|
||
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void; | ||
>subscribe : Symbol(Observable.subscribe, Decl(observableInferenceCanBeMade.ts, 13, 56)) | ||
>next : Symbol(next, Decl(observableInferenceCanBeMade.ts, 14, 14)) | ||
>value : Symbol(value, Decl(observableInferenceCanBeMade.ts, 14, 22)) | ||
>T : Symbol(T, Decl(observableInferenceCanBeMade.ts, 13, 25)) | ||
>error : Symbol(error, Decl(observableInferenceCanBeMade.ts, 14, 40)) | ||
>error : Symbol(error, Decl(observableInferenceCanBeMade.ts, 14, 50)) | ||
>complete : Symbol(complete, Decl(observableInferenceCanBeMade.ts, 14, 70)) | ||
} | ||
|
||
function asObservable(input: string | ObservableInput<string>): Observable<string> { | ||
>asObservable : Symbol(asObservable, Decl(observableInferenceCanBeMade.ts, 15, 1)) | ||
>input : Symbol(input, Decl(observableInferenceCanBeMade.ts, 17, 22)) | ||
>ObservableInput : Symbol(ObservableInput, Decl(observableInferenceCanBeMade.ts, 9, 1)) | ||
>Observable : Symbol(Observable, Decl(observableInferenceCanBeMade.ts, 10, 64)) | ||
|
||
return typeof input === 'string' ? of(input) : from(input) | ||
>input : Symbol(input, Decl(observableInferenceCanBeMade.ts, 17, 22)) | ||
>of : Symbol(of, Decl(observableInferenceCanBeMade.ts, 0, 0)) | ||
>input : Symbol(input, Decl(observableInferenceCanBeMade.ts, 17, 22)) | ||
>from : Symbol(from, Decl(observableInferenceCanBeMade.ts, 2, 44)) | ||
>input : Symbol(input, Decl(observableInferenceCanBeMade.ts, 17, 22)) | ||
} | ||
|
57 changes: 57 additions & 0 deletions
57
tests/baselines/reference/observableInferenceCanBeMade.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
=== tests/cases/compiler/observableInferenceCanBeMade.ts === | ||
// Repro from #33131 | ||
|
||
declare function of<T>(a: T): Observable<T>; | ||
>of : <T>(a: T) => Observable<T> | ||
>a : T | ||
|
||
declare function from<O extends ObservableInput<any>>(input: O): Observable<ObservedValueOf<O>>; | ||
>from : <O extends ObservableInput<any>>(input: O) => Observable<ObservedValueOf<O>> | ||
>input : O | ||
|
||
type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never; | ||
>ObservedValueOf : ObservedValueOf<O> | ||
|
||
interface Subscribable<T> { | ||
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void; | ||
>subscribe : (next?: ((value: T) => void) | undefined, error?: ((error: any) => void) | undefined, complete?: (() => void) | undefined) => void | ||
>next : ((value: T) => void) | undefined | ||
>value : T | ||
>error : ((error: any) => void) | undefined | ||
>error : any | ||
>complete : (() => void) | undefined | ||
} | ||
type ObservableInput<T> = Subscribable<T> | Subscribable<never>; | ||
>ObservableInput : ObservableInput<T> | ||
|
||
|
||
declare class Observable<T> implements Subscribable<T> { | ||
>Observable : Observable<T> | ||
|
||
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void; | ||
>subscribe : (next?: ((value: T) => void) | undefined, error?: ((error: any) => void) | undefined, complete?: (() => void) | undefined) => void | ||
>next : ((value: T) => void) | undefined | ||
>value : T | ||
>error : ((error: any) => void) | undefined | ||
>error : any | ||
>complete : (() => void) | undefined | ||
} | ||
|
||
function asObservable(input: string | ObservableInput<string>): Observable<string> { | ||
>asObservable : (input: string | Subscribable<never> | Subscribable<string>) => Observable<string> | ||
>input : string | Subscribable<never> | Subscribable<string> | ||
|
||
return typeof input === 'string' ? of(input) : from(input) | ||
>typeof input === 'string' ? of(input) : from(input) : Observable<string> | ||
>typeof input === 'string' : boolean | ||
>typeof input : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | ||
>input : string | Subscribable<never> | Subscribable<string> | ||
>'string' : "string" | ||
>of(input) : Observable<string> | ||
>of : <T>(a: T) => Observable<T> | ||
>input : string | ||
>from(input) : Observable<string> | ||
>from : <O extends ObservableInput<any>>(input: O) => Observable<ObservedValueOf<O>> | ||
>input : ObservableInput<string> | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @strict: true | ||
|
||
// Repro from #33131 | ||
|
||
declare function of<T>(a: T): Observable<T>; | ||
declare function from<O extends ObservableInput<any>>(input: O): Observable<ObservedValueOf<O>>; | ||
|
||
type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never; | ||
|
||
interface Subscribable<T> { | ||
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void; | ||
} | ||
type ObservableInput<T> = Subscribable<T> | Subscribable<never>; | ||
|
||
|
||
declare class Observable<T> implements Subscribable<T> { | ||
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void; | ||
} | ||
|
||
function asObservable(input: string | ObservableInput<string>): Observable<string> { | ||
return typeof input === 'string' ? of(input) : from(input) | ||
} |