Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using without JSX forces to pass down all props #583

Closed
owais opened this issue Jan 1, 2019 · 4 comments
Closed

Using without JSX forces to pass down all props #583

owais opened this issue Jan 1, 2019 · 4 comments
Milestone

Comments

@owais
Copy link

owais commented Jan 1, 2019

Trying to use this lib with typescript but without using JSX forces to pass down all defined props unlike with JSX. Unless this is a bug in typescript or some tooling, components should define default values or make the props optional if they are not truly required. That is how it seems to work with JSX.

import React, {Component} from 'react';
import h from 'react-hyperscript';

import TopAppBar from '@material/react-top-app-bar';
import MaterialIcon from '@material/react-material-icon';

class App extends Component {
  render() {
    return (
      h('div',
        h(TopAppBar, {
          title: 'Pro App',
          navigationIcon: h(MaterialIcon, {icon: 'menu', onClick: () => console.log('click')}),
          actionItems: [h(MaterialIcon, {key: 'item', icon: 'bookmark'})]
        })
      )
    )
  }
}
/app/src/App.tsx
Type error: Argument of type '{ title: string; navigationIcon: any; actionItems: any[]; }' is not assignable to parameter of type 'Props'.
  Type '{ title: string; navigationIcon: any; actionItems: any[]; }' is missing the following properties from type 'TopAppBarProps': className, dense, fixed, prominent, and 3 more.  TS2345
@moog16
Copy link
Contributor

moog16 commented Jan 2, 2019

hmm this seems to be an issue with top app bar...the props listed should be optional. The component comes with default props, which is why it was never an issue for us. I'm not sure why react-hyperscript doesn't pick up the default props.

Just opening this PR which should fix your issue. In the meantime as a workaround, can you merge your props with TopAppBar.defaultProps?
#587

@moog16 moog16 added this to the 0.9.0 milestone Jan 2, 2019
@owais
Copy link
Author

owais commented Jan 3, 2019

Thanks. I was testing on a toy-app/side-project so it's not urgent for me at all to use the workaround. Note that I only tested TopAppBar component with Typescript and React.createElement or hyperscript instead of JSX. Other components might have similar issues as well.

@moog16
Copy link
Contributor

moog16 commented Jan 4, 2019

merged #587

@moog16 moog16 closed this as completed Jan 4, 2019
@owais
Copy link
Author

owais commented Jan 5, 2019

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants