You're mixing up runtime with compile time. TS doesn't know in compile time that 'key1' exists. If you explicitly write const key1 = props['key1'] it will infer it as unknown, because you said that props[string] = unknown.
Comments
Log in with your Bluesky account to leave a comment
Yes, because key1 and key2 lost inference to T after destructuring (rest is inferred as Omit which makes sense). After you've captured T you can explictly tell it that key1 = T['key1']. Heres two ways to go about it.
Alright, somehow I cannot wrap around to how it can infer rest but not key1 and key2, but that's probable a me-problem 😅 The examples you pass are helpful, I guess I just wish it would not be needed to do double bookkeeping.
Thanks anyway for guiding me and I hope you are doing well! 🫶
Comments
https://tsplay.dev/NVBkBN
Thanks anyway for guiding me and I hope you are doing well! 🫶