Skip to content

Instantly share code, notes, and snippets.

@Minozzzi
Created March 15, 2024 21:53
Show Gist options
  • Save Minozzzi/7330d4c8b518b62674b5e6563f9939f5 to your computer and use it in GitHub Desktop.
Save Minozzzi/7330d4c8b518b62674b5e6563f9939f5 to your computer and use it in GitHub Desktop.
This type accepts at least one property
type AtLeastOnePropertyOf<T, K extends keyof T> = K extends K ? Record<K, T[K]> : never
type User = {
name: string;
age: number;
}
type UpdateUser = AtLeastOnePropertyOf<User, keyof User> & Partial<User>
const user = {
name: 'name',
age: 10
};
function updateAtLeastOne(user: User, newUser: UpdateUser) {
}
updateAtLeastOne(user, {
age: 20
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment