CompatibleProperty
Resolves a type union of property name literals within type `T` whose property values are assignable to type `CompatibleValue`. Use case: “I want to know which properties of `T` are compatible with `CompatibleValue`.”
Installation
npx atmx add type compatible-property
Copy and paste the following method into @/utils/helpers/undefined.ts
:
import type { BoxedPrimitive } from "@/types/boxed-primitive.ts";import type { Any } from "@/types/any.ts";
/*** Resolves a type union of property name literals within type `T`* whose property values are assignable to type `CompatibleValue`.** Use case: “I want to know which properties of `T` are compatible* with `CompatibleValue`.”*/export type CompatibleProperty<T, CompatibleValue> = [T] extends [Any]? keyof any: T extends null | undefined? never: { [P in keyof BoxedPrimitive<T>]: BoxedPrimitive<T>[P] extends CompatibleValue ? P : never; }[keyof BoxedPrimitive<T>];