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

typeof ignoring early return when used in object with string keys #48307

Closed
equal-matt opened this issue Mar 17, 2022 · 3 comments Β· Fixed by #48427
Closed

typeof ignoring early return when used in object with string keys #48307

equal-matt opened this issue Mar 17, 2022 · 3 comments Β· Fixed by #48427
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@equal-matt
Copy link

Bug Report

πŸ”Ž Search Terms

typeof, guard, early return, object, keys, null

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about everything(?)

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function doSomething() {
    const myThing = Math.random() > 0.5 ? { foo: 'bar' } : null;
    if (!myThing) return;

    const okayThing: { foo: typeof myThing.foo } = { foo: 'bar' }
    const notOkayThing: { [key: string]: typeof myThing.foo } = { foo: 'bar' }
    // Error: Object is possibly 'null'
}

πŸ™ Actual behavior

notOkayThing errors with Object is possibly 'null'.

πŸ™‚ Expected behavior

Types for values in okayThing and notOkayThing should be equivalent.

@ritikBhandari
Copy link

hi,
Can i try to solve this issue?

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Mar 17, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 17, 2022
@Blopaa
Copy link
Contributor

Blopaa commented Mar 23, 2022

@ritikBhandari are you working on this issue ? If not I would like to try to resolve the issue.

@ritikBhandari
Copy link

@Blopaa I'm working on another issue. You can try it! :)

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

Successfully merging a pull request may close this issue.

4 participants