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

Added typescript typings file #57

Merged
merged 1 commit into from
Oct 3, 2017
Merged

Conversation

vasilevich
Copy link

This pull request contains a simple index.d.ts file and package.json configuration to point to it.
it allows you to seamlessly use this library inside your react-redux project while also utilizing typescript typings.

I think it will also allow IDEs such as VSCODE to hint better while using this library.
Here is a typical usage example in a typical typescript project:

import * as React from 'react';
import {Provider} from 'react-redux';
import store from 'reducers';
import RouterPage from 'containers/RouterPage';
import I18n from 'redux-i18n';

/**
 * Entrance of app
 * The program starts here
 * first we grab our app store
 * and then we place our main app route which is our pages routes switch
 */

export class App extends React.Component<object, object> {
  render() {
    return (
      <Provider store={store}>
        <I18n translations={{
          es: {
            '_hello_': 'Traduce este texto',
            'Hello {n}!': 'Hola {n}!',
          },
        }} initialLang="es">
          <RouterPage/>
        </I18n>
      </Provider>
    );
  }
}

Which might look similar to normal JS. however without the typings, it would not let you import I18n as easily within typescript projects.

and then, in any child component within <RouterPage/>

example typescript usage:

import * as React from 'react';
import {Container, Image, Grid} from 'semantic-ui-react';
import {ControlProps} from 'containers/ControlPage';
import FullScreenButton from 'components/Control/Components/Navigation/Components/MenuManager/Components/MenuLink/FullScreenButton';
import {fullHeightStyle} from 'utils/Style';
import {PropTypes} from 'react';
import {IGetTranslateFunctionResponse} from 'redux-i18n';

export default class Main extends React.Component<ControlProps, never> {

  static contextTypes = {
    t: PropTypes.func.isRequired,
  };
  context: { t: IGetTranslateFunctionResponse };
  constructor(props: ControlProps) {
    super(props);
  }
  render() {
    return (
      <Container style={fullHeightStyle} fluid>
        <Grid>
          <Grid.Column width={14}>
            <Image centered src="https://react.semantic-ui.com/assets/images/wireframe/image.png"/>
            <div>{this.context.t('_hello_')}</div>
          </Grid.Column>
          <Grid.Column width={1}>
            <FullScreenButton {...this.props} />
          </Grid.Column>
        </Grid>
      </Container>
    );
  }
}

thank you for your time!
cheers.

@francescarpi
Copy link
Member

Thanks!

@francescarpi francescarpi merged commit b5ca2f2 into APSL:master Oct 3, 2017
@renchap renchap mentioned this pull request Jan 9, 2018
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

Successfully merging this pull request may close these issues.

2 participants