Skip to content

The function that async function return can not infer when type definition mixed #29196

Closed
@ArrayZoneYour

Description

@ArrayZoneYour

TypeScript Version: 3.2.2

Search Terms: Promise, function return type

Code

Example 1

const increment: (
  num: number,
  str: string
) => Promise<((s: string) => any) | string> | string = async (num, str) => {
  // return ''
  return a => {
    return a.length
  }
}

Exmaple 2

const increment: (
  num: number,
  str: string
) => Promise<((s: string) => any) | string> = async (num, str) => {
  // return ''
  return a => {
    return a.length
  }
}

Expected behavior:

type of a is string

Actual behavior:

a in Example 1 doesn't have type

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Contextual TypesThe issue relates to contextual types

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions