We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
ObjectValue sounds like be GivenObject[GivenKey], but it doesn't seem to be exactly the same.
GivenObject[GivenKey]
Playground Link
import { ObjectValue, ToString } from "type-fest/source/internal"; type ObjectT = { 0: number '1': number } declare const a: ObjectT['0'] //=> number declare const b: ObjectT[0] //=> number declare const c: ObjectT[1] //=> number declare const d: ObjectT['1'] //=> number // ObjectValue's behavior sounds like ObjectT[Key], but 👇🏻: declare const e: ObjectValue<ObjectT, 0> //=> number declare const f: ObjectValue<ObjectT, '0'> //=> never ❌ declare const g: ObjectValue<ObjectT, 1> //=> never ❌ declare const h: ObjectValue<ObjectT, '1'> //=> number // new type type ObjectValue1<T, K> = K extends keyof T ? T[K] : ToString<K> extends keyof T ? T[ToString<K>] : K extends `${infer NumberK extends number}` ? NumberK extends keyof T ? T[NumberK] : never : never; // worked! declare const i: ObjectValue1<ObjectT, '0'> //=> number ✅ declare const j: ObjectValue1<ObjectT, 1> //=> number ✅
The text was updated successfully, but these errors were encountered:
@sindresorhus
Sorry, something went wrong.
ObjectValue
Successfully merging a pull request may close this issue.
ObjectValue sounds like be
GivenObject[GivenKey]
, but it doesn't seem to be exactly the same.Playground Link
Upvote & Fund
The text was updated successfully, but these errors were encountered: