question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extend default props interface to support custom props (Typescript)

See original GitHub issue

I have gone through these following points

Issue Description

node, npm, react-native, react and native-base version, expo version if used, xcode version

  • node - v8.12.0
  • npm - 6.5.0
  • react-native - 0.59
  • native-base - 2.13.4
  • expo - 33
  • xcode - 10.2.1

Hi, thank you for you library, it’s awesome. I am wondering if there is a way to customize current typescript interfaces to support my custom prop styles from theme folder?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
KowalskiPcommented, Jul 29, 2019

For example I want to have a way to use this:

<Button myCustomPropStyle />

Without using ts-ignore above

1reaction
connor-odohertycommented, Jan 23, 2020

@mccordgh I solved this by using a similar pattern to @RioFiveJack, but extending the interface instead of overwriting it as my original solution did:

declare module "native-base" {
  namespace NativeBase {
    interface Card extends CustomStyleProps {}
  }
}

interface CustomStyleProps {
  noShadow?: boolean;
  whiteBackground?: boolean;
  noPadding?: boolean;
  noBorder?: boolean;
  cardBody?: boolean;
}

interface IProps extends CustomStyleProps {}

export class Card extends Component<IProps> {
  render() {
    return <NBCard {...this.props} />;
  }
}

Is this the use case you’re looking for?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typing defaultProps - React TypeScript Cheatsheets
A component with defaultProps may seem to have some required props that actually aren't. Problem Statement​. Here's what you want to do: interface...
Read more >
Default Props in React/TypeScript - DEV Community ‍ ‍
It seems to me that interfaces are the "default" TypeScript way to ... interface Props extends PropsWithChildren<any>{ requiredString: ...
Read more >
How to extend a component to add default props in React/TS
You can do that by using the React.ComponentProps ¹ utility type to get the type of the props of DataGrid , and TypeScript's...
Read more >
Use Interface Props in Functional Components ... - Pluralsight
Writing function or class components in a React/TypeScript app often requires you to define the type of props passed to them.
Read more >
How to Overload TypeScript React Component Interfaces by ...
Bonus tip: A simple way to extend this to include unionized interface overloading to your custom props could be to follow a pattern...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found