Skip to content

Instantly share code, notes, and snippets.

@emmiep
Created March 7, 2018 17:29
Show Gist options
  • Save emmiep/0595a88f89456900eb392b855642244a to your computer and use it in GitHub Desktop.
Save emmiep/0595a88f89456900eb392b855642244a to your computer and use it in GitHub Desktop.
Create a type with only nullable properties from another
interface VeryStrict {
name: string,
value: any
}
type Whatever = {
[K in keyof VeryStrict]?: VeryStrict[K]
};
const defaults: VeryStrict = {
name: 'default',
value: 123
};
// Does not work
// const o1: VeryStrict = {};
const o2: Whatever = {
name: 'works'
};
// Doesn't work either
// const o3: VeryStrict = o2;
// combine both types
const o4: VeryStrict = Object.assign({}, defaults, o2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment