Skip to content

Commit

Permalink
fix: fix Snackbar static constants type for typescript (#609)
Browse files Browse the repository at this point in the history
### Motivation

Below `Snackbar` usage has error.

<img width="332" alt="2018-10-18 20 18 21" src="https://user-images.githubusercontent.com/434227/47150896-19790100-d313-11e8-8794-256703ab654b.png">

And error message:

```
path/to/my/component.tsx:131:17 - error TS2322: Type 'string' is not assignable to type 'number | undefined'.

131                 duration={Snackbar.DURATION_SHORT}
                    ~~~~~~~~

  node_modules/react-native-paper/typings/components/Snackbar.d.ts:10:3
    10   duration?: number;
         ~~~~~~~~
    The expected type comes from property 'duration' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Snackbar> & Readonly<{ children?: ReactNode; }> & Readonly<SnackbarProps>'
```

Because `duration` was defined as a `string` in the type definition file. I fixed it.

### Test plan

Typecheck for below jsx.

```jsx
<Snackbar
    visible={true}
    duration={Snackbar.DURATION_SHORT}>
    Foo
</Snackbar>
```
  • Loading branch information
Yukiya Nakagawa authored and satya164 committed Oct 18, 2018
1 parent 0697fb6 commit 2969b1d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions typings/components/Snackbar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface SnackbarProps {
}

export declare class Snackbar extends React.Component<SnackbarProps> {
static DURATION_SHORT: string;
static DURATION_MEDIUM: string;
static DURATION_LONG: string;
static DURATION_SHORT: number;
static DURATION_MEDIUM: number;
static DURATION_LONG: number;
}

0 comments on commit 2969b1d

Please sign in to comment.