Skip to content

from() does not infer type correctly with TS 3.6 #4992

Closed
@felixfbecker

Description

@felixfbecker

Bug Report

Current Behavior

Type 'Observable<unknown>' is not assignable to type 'Observable<string>'.
  Type 'unknown' is not assignable to type 'string'.ts(2322)

Reproduction

function asObservable(input: string | ObservableInput<string>): Observable<string> {
    return typeof input === 'string' ? of(input) : from(input)
}

Expected behavior
Should compile

Environment

  • RxJS version: 6.5.2
  • TS version: 3.6.2

Possible Solution
Instead of using ObservedValueOf<T>:

export declare function from<O extends ObservableInput<any>>(input: O): Observable<ObservedValueOf<O>>

declare from like:

export declare function from<O>(input: ObservableInput<O>): Observable<O>

this seems to work.

Additional context/Screenshots
2019-08-29 10 49 04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions