Created
March 7, 2018 17:29
-
-
Save emmiep/0595a88f89456900eb392b855642244a to your computer and use it in GitHub Desktop.
Create a type with only nullable properties from another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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