mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
refactor(react): replace prototype-walking and inferred class props (#1376)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,20 +22,3 @@ export type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
||||
export type NonNullableObject<T extends object> = {
|
||||
[P in keyof T]-?: Exclude<T[P], null | undefined>;
|
||||
};
|
||||
|
||||
// Detects readonly vs writable properties via conditional type identity check.
|
||||
type IfEquals<X, Y, A, B> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B;
|
||||
|
||||
type WritableKeys<T> = {
|
||||
[K in keyof T]-?: IfEquals<{ [Q in K]: T[K] }, { -readonly [Q in K]: T[K] }, K, never>;
|
||||
}[keyof T];
|
||||
|
||||
type SettableKeys<T> = {
|
||||
[K in WritableKeys<T>]: T[K] extends (...args: any[]) => any ? never : K;
|
||||
}[WritableKeys<T>];
|
||||
|
||||
type ExcludeInternal<K> = K extends `_${string}` ? never : K;
|
||||
|
||||
export type InferClassProps<D extends abstract new (...args: any[]) => any> = Partial<
|
||||
Pick<InstanceType<D>, ExcludeInternal<SettableKeys<InstanceType<D>>>>
|
||||
>;
|
||||
|
||||
Reference in New Issue
Block a user