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

type inference of nested type property #56979

Closed
kim-jaedeok opened this issue Jan 8, 2024 · 2 comments
Closed

type inference of nested type property #56979

kim-jaedeok opened this issue Jan 8, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@kim-jaedeok
Copy link

πŸ”Ž Search Terms

"type inference", "property deep inside"

πŸ•— Version & Regression Information

tested at 5.3.3, 4.9.3, 4.6.3

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBAglC8AoKUA+UDeUwCcD2YAXJlKJMQEQCGFA3FAG5UA2ArhMVgBYCWxATFAC+w4cjQlcBTqXAcoFAEZ1GLdjK4RmzPMQCMokUNqJEAYzwA7AM7AoVBFAAUVYjACUCAHyZx1gO48wGZczlQAdFJg4WQQnhjiKGZU1tDUFISJKFA4EMCsOJb2kfjRTGwQ4bz0APQ1UAAqclAAkpYAZhC5lmbQ-ng4ANbhWcmpCsqZ2dm5+YXOnvA+EVHh5exVWjq19U2QrR1dED3Qlnh2-UMjKEKIxqYWNnaKjk6Kbos+CUlWtpKlongUEUJj8gWCoScq1i8VGKTSNCm0xyeQKRVW60q1SgdUazTanW6vSgl2GcPGSgyWRQszRC282FKazUWK2eB2eP2BKOJxJAzJNzuQA

πŸ’» Code

type A =
  | { prop: { type: "a"; value: { hi: 2 } } }
  | { prop: { type: "b"; value: { hello: 1 } } };

const a = (a: A) => {
  switch (a.prop.type) {
    case "a":
      return a.prop.value.hi; // Type Inference work.
    case "b":
      return () => a.prop.value.hello; // Type Inference not work.
  }
};

const b = (b: A) => {
  const { prop } = b;

  switch (prop.type) {
    case "a":
      return prop.value.hi; // Type Inference work.
    case "b":
      return () => prop.value.hello; // Type Inference work.
  }
}

πŸ™ Actual behavior

When a property deep inside an object is entered in a conditional statement, type inference is not made.

Screenshot 2024-01-08 at 3 52 34β€―PM

πŸ™‚ Expected behavior

type error not occur.

Additional information about the issue

No response

@fatcerberus
Copy link

#18758

@kim-jaedeok kim-jaedeok changed the title type in type inference of nested type property Jan 8, 2024
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 8, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants