Skip to content

Type widening for T or Promise<T>Β #45338

@alexshelkov

Description

@alexshelkov

Bug Report

πŸ”Ž Search Terms

Type widening, promise, generic type widening.

πŸ•— Version & Regression Information

This is the behavior in every version I tried.

⏯ Playground Link

Playground link

πŸ’» Code

type Cb3 = <Res extends string | Promise<string>>(cb: () => Res) => Res

const c: Cb3 = {} as any;

// this don't widen the type, type of t31 is "1"
const t31 = c(() => {
  return '1';
});

// but here is the problem, type of t32 is Promise<string>
const t32 = c(async () => {
  return '1';
});

πŸ™ Actual behavior

Type of t32 is Promise<string>

πŸ™‚ Expected behavior

Type of t32 is Promise<"1">, by analogy with type of t31

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions