Skip to content

Instantly share code, notes, and snippets.

@serjKim
Created October 1, 2025 20:11
Show Gist options
  • Select an option

  • Save serjKim/474e066be42791db0d32b4cd3fbc2178 to your computer and use it in GitHub Desktop.

Select an option

Save serjKim/474e066be42791db0d32b4cd3fbc2178 to your computer and use it in GitHub Desktop.
Test data infer
interface Data {
age?: number;
a: string | null;
c: string;
}
function f<T extends Partial<Data>>(d?: T & { [K in keyof T]: K extends keyof Data ? T[K] : never }): Pick<Data & T, keyof Data> {
return {
c: 'default',
a: 'asd',
...d,
};
}
const x = f({
a: 'asd',
age: 100
});
x.age.toFixed();
x.a.charAt(1);
x.c.toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment