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
If an API returns an object with some dates, such as
interface Resource { id: string; value: number; created: Date; }
The date will become a string due to json conversion:
interface ResourceReturned { id: string; value: number; created: string; }
I want a type such that:
type ResourceReturned = Swap<Resource, Date, string>;
A solution could be
export type Swap<Interface, ReplacedType, ReplacingType> = { [k in keyof Interface]: Interface[k] extends ReplacedType ? ReplacingType : Interface[k]; };
But note that it does not support deep, so it should be perfectionated.
Everyone that has my problem
The text was updated successfully, but these errors were encountered:
I worked on such problem and my idea is:
type _Update<T, U, S> = { 0: Exclude<U, T> extends T ? (Exclude<T, U> | S) : T, 1: S }[[T] extends [U] ? [U] extends [T] ? 1 : 0 : 0] type Update<T extends object, U, S> = { [K in keyof T]: T[K] extends object ? Update<T[K], U, S> : _Update<T[K], U, S> } type a1 = { b1: symbol | string | number b2: symbol | string b3: symbol b4: string b5: { c1: 'c1' c2: number c3: number | symbol } } type test = Update<a1,symbol, boolean>
Sorry, something went wrong.
No branches or pull requests
Is your feature request related to a real problem or use-case?
If an API returns an object with some dates, such as
The date will become a string due to json conversion:
I want a type such that:
Describe a solution including usage in code example
A solution could be
But note that it does not support deep, so it should be perfectionated.
Who does this impact? Who is this for?
Everyone that has my problem
Describe alternatives you've considered (optional)
Additional context (optional)
The text was updated successfully, but these errors were encountered: