microsoft / microsoft/TypeScript

`any` appears to shortcircut structural type checking

Open
#31,295 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: check: Variance Relationships Domain: Conditional Types
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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: link

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the TypeScript 3.5.0-dev.20190507 example in the linked Playground and verify the reported assignability and inferred property types. Trace the type-checker behavior for conditional types involving any, never, and structural assignability; done means the example follows one of the stated expected behaviors without breaking the corresponding type-system rules.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.