Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

any appears to shortcircut structural type checking #31295

Copy link
Copy link
@webstrand

Description

@webstrand
Issue body actions

TypeScript Version: 3.5.0-dev.20190507

Search Terms:
any, unsound, extends, never

Code

// I detect if F is `any` by checking if F extends `never`.
// (F extends never ? true : false) produces `true|false` for `F = any`
// and `false` or `never` for everything else.
type Decider<F> = {
	prop: (F extends never ? true : false) extends false ? "isNotAny" : "isAny";
};

let foo!: Decider<string>;
let bar: Decider<any> = foo;

let fooProp: "isNotAny" = foo.prop;
let barProp: "isAny" = bar.prop;

Expected behavior:
Either bar.prop should have the type "isAny"|"isNotAny" or foo should not be assignable to bar.

Actual behavior:
foo is assignable to bar and bar.prop has the type "isAny" which is incompatible with foo.prop's "isNotAny".

Playground Link: ; let bar: Decider = foo; let fooProp: "isNotAny" = foo.prop; let barProp: "isAny" = bar.prop;" rel="nofollow">link

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.