Skip to content

Instantly share code, notes, and snippets.

@jcalz

jcalz/test.ts Secret

Created May 16, 2018 15:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcalz/32e730f310bca1c0b767036813ea6745 to your computer and use it in GitHub Desktop.
Save jcalz/32e730f310bca1c0b767036813ea6745 to your computer and use it in GitHub Desktop.
type CustomType<K extends keyof any> = {
[P in K]: number
};
type Config<K extends keyof any> = {
[P in K]?: {
highPriority: boolean;
callback: (values: any[]) => number[];
}
};
declare const customFunction:
<K extends keyof any>(values: Record<K, any>[], config: Config<K>) => Array<CustomType<K>>
const values = [
{
foo: 'foo',
bar: 'bar'
},
{
foo: 'foo',
bar: 'bar'
}
];
const config = {
foo: {
highPriority: true,
callback: () => []
},
wrong: {
highPriority: true,
callback: () => []
}
};
// error as desired
const result = customFunction(values, config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment