Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersection Types/function (something like assert): TS7030 TS2345 #30064

Closed
zaoqi opened this issue Feb 23, 2019 · 2 comments
Closed

Intersection Types/function (something like assert): TS7030 TS2345 #30064

zaoqi opened this issue Feb 23, 2019 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@zaoqi
Copy link

zaoqi commented Feb 23, 2019

TypeScript Version: 3.3.3333

Search Terms:

Code

    const assert: ((x: false) => nerver) & ((x: true) => void) = (x: boolean) => {
        if (x === false) {
            return error()
        }
    }

Expected behavior:

Actual behavior:

lang.ts:1257:66 - error TS7030: Not all code paths return a value.

1257     const assert: ((x: false) => nerver) & ((x: true) => void) = (x: boolean) => {

lang.ts:1345:20 - error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'true'.

1345             assert(!eof())

Playground Link:

Related Issues:

@zaoqi zaoqi changed the title Intersection Types/function Intersection Types/function (assert) Feb 23, 2019
@zaoqi zaoqi changed the title Intersection Types/function (assert) Intersection Types/function (something like assert) Feb 23, 2019
@zaoqi zaoqi changed the title Intersection Types/function (something like assert) Intersection Types/function (something like assert): TS7030 TS2345 Feb 23, 2019
@yortus
Copy link
Contributor

yortus commented Feb 24, 2019

This CFA-based approach to handling assert functions is covered in #8655. E.g. see #8655 (comment).

That was closed as a design limitation. There is some reasoning and a future possible solution described in #8655 (comment)

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 26, 2019
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants