Skip to content

TypeScript strangely expanding out boolean into true/false in type alias. #30029

Closed
@CyrusNajmabadi

Description

@CyrusNajmabadi

Using TS 3.3.1. strictNullChecks, noImplicitAny.
Code in question:

interface pojo { b: boolean }

type primitive = Function | string | number | boolean | undefined | null;
type SimpleInput<T> = T | Promise<T>;

type Input<T> =
    T extends primitive ? SimpleInput<T> :
    T extends object ? SimpleInput<InputObject<T>> :
    never;

type InputObject<T> = {
    [P in keyof T]: Input<T[P]>;
}

var ip2: Input<pojo> = { b: Promise.resolve(true) };

Error is reported as:

Type '{ b: Promise<boolean>; }' is not assignable to type 'SimpleInput<InputObject<pojo>>'.
  Type '{ b: Promise<boolean>; }' is not assignable to type 'InputObject<pojo>'.
    Types of property 'b' are incompatible.
      Type 'Promise<boolean>' is not assignable to type 'boolean | Promise<false> | Promise<true>'.
        Type 'Promise<boolean>' is not assignable to type 'Promise<false>'.
          Type 'boolean' is not assignable to type 'false'.

It's unclear to me why/how this is happening. The expansion of Input<pojo.b> seems to have become boolean | Promise<true> | Promise<false> instead of boolean | Promise<boolean>.

is this expected? a bug? If intentional, is there some sort of workaround?

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