Skip to content

Conditional types split function return type boolean to two separate functions #37279

@moshest

Description

@moshest

TypeScript Version: 3.8.3

Search Terms: return type true false instead of boolean

Expected behavior: Template should resolved to a () => boolean function

Actual behavior: Template resolved to (() => true) | (() => false)

Related Issues:

Code

type Func<T> = T extends never ? never : (() => T);

const foo: Func<boolean> = Boolean;

// Type 'BooleanConstructor' is not assignable to type '(() => false) | (() => true)'.
//   Type 'BooleanConstructor' is not assignable to type '() => false'.
//     Type 'boolean' is not assignable to type 'false'.(2322)
Output
"use strict";
const foo = Boolean;
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}

Playground Link: Provided

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