Created
December 14, 2021 01:10
-
-
Save akaptur/e4d4ead04645ca1e1190e648f8403e9e to your computer and use it in GitHub Desktop.
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
type Account = { | |
name: string, | |
balance: string, | |
} | |
function makeAccount({ | |
name = "foo", | |
balance = "10.05" | |
}: Partial<Account> = {}): Account { | |
return {name, balance} | |
} | |
makeAccount() // a caller can take all the default options | |
makeAccount({balance: "0.00"}) // or override one or more | |
makeAccount({name_with_typo: "foo"}) // TS correctly emits an error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment