Skip to content

Type information is lost when retrieving Subscribable<T> value #2555

@craxal

Description

@craxal

Consider the following code:

import * as ko from "knockout";
let obj: ko.Subscribable<number> = ko.observable(5);
let result = obj();

Here, I expect TypeScript to deduce the type for result to be number. However, it deduces the type to be any. This can be attributed to the fact that the base type (SubscribableFunctions<T>) extends Function, which discards the type parameter.

This can be fixed by modifying the Subscribable<T> type declaration to reflect Observable<T>:

export interface Subscribable<T = any> extends SubscribableFunctions<T> {
    (): T
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions