basarat / basarat/typescript-book

Object creation with defaults

Open
#284 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
21.6k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Add to tips somewhere.

https://stackoverflow.com/a/44124349/390330

```ts
interface Model {
content: string;
count: number
}

function createModel({
// Add defaults
content = '',
count = 0
} = {}): Model {
return { content, count }
}

createModel(); // Okay
createModel({ count: 1 }); // Okay
createModel({ counted: 1 }); // Error: Typo
```
:rose:

Contributor guide

Open the contributing guide

Research direction

Find the repository's tips section and review how similar TypeScript examples are organized. Use the linked Stack Overflow answer and the example in this issue as the content reference; done means the object-creation-with-defaults guidance is added in the appropriate tips location.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.