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

Improved typescript support #2912

Merged
merged 3 commits into from Jul 11, 2021
Merged

Improved typescript support #2912

merged 3 commits into from Jul 11, 2021

Conversation

GianlucaGuarini
Copy link
Member

@GianlucaGuarini GianlucaGuarini commented May 15, 2021

This PR is a breaking change and adds the withTypes method in order to get a better typescript support to Riot.js components.

The new method allows us writing components as follows:

<my-component>
  <p>{ state.greeting }{ props.username }</p>

  <!--
    Notice that lang="ts" does actually nothing.
    It's just needed to let your IDE interpret the below code as typescript.
    The riot compiler will ignore it
  -->
  <script lang="ts">
    import {withTypes, RiotComponent} from 'riot'

    export type MyComponentProps = {
      username: string
    }

    export type MyComponentState = {
      message: string
    }

    export type MyComponent = RiotComponent<MyComponentProps, MyComponentState>

    export default withTypes<MyComponent>({
      state: {
        message: 'hello'
      }
    })
  </script>
</my-component>

This is a breaking change that requires a new RIot and Compiler release.

@GianlucaGuarini GianlucaGuarini changed the title Feature/new types Improved typescript support May 15, 2021
@kachurun
Copy link
Contributor

I love you dude, I crutched it in my project three days ago. Now this is not needed and everything will work natively. Perfect!

@GianlucaGuarini GianlucaGuarini merged commit da98b94 into dev Jul 11, 2021
@GianlucaGuarini GianlucaGuarini deleted the feature/new-types branch July 11, 2021 12:34
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.

None yet

2 participants