Skip to content

Suggestion: consolidate generics in union if they match #31955

@OliverJAsh

Description

@OliverJAsh

TypeScript Version: 3.5.2

Search Terms: rxjs startWith generics union consolidate same

Code

declare const create: <T>(
    t: T,
) => {
    startWith: <D>(v1: D) => T | D;
};

// Succeeds
// $ExpectType { foo: number } | { bar: number }
const r1 = create({ foo: 1 }).startWith({ bar: 1 });

// Fails
// $ExpectType { foo: number }
// Actual: { foo: number } | { foo: number }
const r2 = create({ foo: 1 }).startWith({ foo: 1 });

Although the expected/actual types are compatible, it's slightly irritating to deal with a union type T | T instead of a consolidated type T, as it makes type inspection in VS Code much more difficult (especially when the types are large or deeply nested).

Real world use case: ReactiveX/rxjs#4866

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions