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
题目链接:Merge,答题
实现 Merge 类型,将两个类型合并为一个新的类型,如果两个类型中有相同的 key,后一个类型的 key 覆盖前面一个类型的 key
Merge
key
import type { Equal, Expect } from "@type-challenges/utils"; type Foo = { a: number; b: string; }; type Bar = { b: number; c: boolean; }; type cases = [ Expect< Equal< Merge<Foo, Bar>, { a: number; b: number; c: boolean; } > > ];
type Merge<T, U> = { [K in keyof T | keyof U]: K extends keyof U ? U[K] : K extends keyof T ? T[K] : never; };
type Merge<T, U> = { [K in keyof (T & U)]: K extends keyof U ? U[K] : K extends keyof T ? T[K] : never; };
type Merge<T, U> = Omit<Omit<T, keyof U> & U, never>;
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目
题目链接:Merge,答题
实现
Merge
类型,将两个类型合并为一个新的类型,如果两个类型中有相同的key
,后一个类型的key
覆盖前面一个类型的key
答案
方法一
方法二
方法三
The text was updated successfully, but these errors were encountered: