Skip to content

Why are generics not deducing nested objects correctly? #57658

Closed
@masterYi2333

Description

@masterYi2333

🔎 Search Terms

Generic derivation

🕗 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?ts=5.3.3#code/C4TwDgpgBAggdiAShAxgewE4BMoF4rLrYA8AzsBgJZwDmANFAIYIB8A3AFCiRQBmceKMQAqUCAA9gEOFlJQA3kwBcsBIUw4AviwAUYRhkYBbUisWMVwgNoAiRjYC6UTQEo8LKNbuPOHdHHIoACMVfkE9A2NSN1wPeQ4oRKgMCGAAVwwBfUMTADpGDk1ff0CUQSCdeMSLBQSkxgBGFQaAJgBmOjrNTtdOIA

💻 Code

// Your code here
type AnyRecord = Record<string, any>;
type fn = <T extends { a: AnyRecord }>(params: { a: T["a"] }) => T["a"];

const b: fn = (params) => {
    return params.a
};

const c = b({
  a: {
    a1: 123,
  },
});

🙁 Actual behavior

Why isn't c deduced to the type I actually passed in?

🙂 Expected behavior

c is deduced to the type I actually passed in

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