Skip to content

Instantly share code, notes, and snippets.

@akaptur
Created December 14, 2021 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akaptur/e4d4ead04645ca1e1190e648f8403e9e to your computer and use it in GitHub Desktop.
Save akaptur/e4d4ead04645ca1e1190e648f8403e9e to your computer and use it in GitHub Desktop.
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