basarat / basarat/typescript-book

Destructuring arguments

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

Description

e.g :

``` ts
function test({ x, y }: { x: number, y: number }) {
console.log(x, y);
}

test({
x: 1,
y: 2
});
```

with defaults :

``` ts
function test({ x = 123, y = 456 } = {}) {
console.log(x, y);
}

test({
x: 1,
y: 2
});
```

with defaults and type annotation:

``` ts
function test({ x = 123, y = 456 }: { x?: number, y?: number } = {}) {
console.log(x, y);
}

test({
x: 1,
y: 2
});

```

Also https://blog.mariusschulz.com/2015/11/13/typing-destructured-object-parameters-in-typescript

Contributor guide

Open the contributing guide

Research direction

No repository file or test is named. Start by reviewing the destructuring examples in the issue and the linked TypeScript article, then locate the relevant book section. Done means the book explains object-parameter destructuring, defaults, and type annotations with accurate examples.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.