Skip to content

"Property does not exist on type 'never'" with optional chaining #58733

Closed as not planned
@JorensM

Description

@JorensM

🔎 Search Terms

optional chaining, null, undefined, property does not exist on type never

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBACgTgewFYQMbCgXigbwFBRQCWAJgFxQB2ArgLYBGEcBUwRwANhBQM7BxFKAcwA0LDoIDWvfoNEsSEHqgFg2CSjIHC8AXzx4uGMIhToK8ZGgwAfKtQ4cs9xwG4DqDTwRcAdBwQhAAoTK3QAfl82TggASnc8IA

💻 Code

type Project = {
  id: number
  title: string,
  link: string,
  description: string
}

let project: Project | null = null;

console.log(project?.title);

🙁 Actual behavior

TypeScript is not recognizing that project can be of type Project, giving a type error:

Property 'title' does not exist on type 'never'.

🙂 Expected behavior

I would expect for TypeScript to accept Project as a possible type for the variable.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions