mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-13 18:14:48 -05:00
Add regression test
This commit is contained in:
22
tests/cases/compiler/observableInferenceCanBeMade.ts
Normal file
22
tests/cases/compiler/observableInferenceCanBeMade.ts
Normal file
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user