[Typescript] Default props from defaults when destructuring

Open
#358 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
react, typescript

Research direction

No files, tests, or entry points are named in the issue. Start by locating the TypeScript and React prop/defaultProps handling, then determine whether destructuring can use defaults from static defaultProps; done means the documented example behaves as requested and is covered by a test.

Written by the indexing model from the issue text.

Description

The defaults work fine from the static .defaultProps property like ...

interface Props {
  foo?: string;
}

const Test: React.SFC<Props> = (props: Props) => {
  const { foo, ...rest } = props;

  return (
    <div { ...rest } />
  );
}

Test.defaultProps = {
  foo: 'bar',
};

export default Test;

I'm wondering if you think it would be possible to get default prop values from the defaults when destructuring during the render? like ...

interface Props {
  foo?: string;
}

const Test: React.SFC<Props> = (props: Props) => {
  const { foo = 'bar', ...rest } = props;

   return (
    <div { ...rest } />
  );
};

export default Test;
Dominant language
TypeScript
Stars
3.8k
Forks
316
Avg merge
3h 28m
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from reactjs/react-docgen

All issues in reactjs/react-docgen

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.