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

Indexed Access Types that should be the same as a given types are somehow different than that type, under strictNullChecks #30871

Closed
Ryan1729 opened this issue Apr 11, 2019 · 2 comments · Fixed by #30779
Assignees
Labels
Bug A bug in TypeScript

Comments

@Ryan1729
Copy link

TypeScript Version: 3.5.0-dev.20190411

Search Terms:
Indexed Access Types
Lookup Types
strictNullChecks

Code

type Foo = {bar: undefined} | {bar: string};

const b1: {bar: Foo["bar"]} = {bar: undefined};
const b2: Foo = b1;
const b3: Foo = {bar: undefined};

Expected behavior:
This should compile with strictNullChecks on. I expect {bar: Foo["bar"]} to be the same thing as Foo in this case.
Actual behavior:
running tsc --strictNullChecks .\bug.ts result in:

bug.ts:4:7 - error TS2322: Type '{ bar: string | undefined; }' is not assignable
 to type 'Foo'.
  Type '{ bar: string | undefined; }' is not assignable to type '{ bar: string;
}'.
    Types of property 'bar' are incompatible.
      Type 'string | undefined' is not assignable to type 'string'.
        Type 'undefined' is not assignable to type 'string'.

4 const b2: Foo = b1;
        ~~


Found 1 error.

Playground Link: Link

Related Issues:
#29042
#21975 This one is extremely similar but it and the ones it was marked as a duplicate of were closed. Is this a regression?

@jack-williams
Copy link
Collaborator

Might be fixed by #30779

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Apr 11, 2019
@RyanCavanaugh
Copy link
Member

Might be fixed by #30779

Confirmed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants