Bit: Typescript compiler v0.05 does not support decorators

Created on 27 Mar 2019  路  5Comments  路  Source: teambit/bit

Expected Behavior

The bit/envs/compilers/typescript compiler should support decorators contained within exported components.

Actual Behavior

The components compile fine, however at runtime in both the playground and when installing via npm/yarn the resulting component does not work correctly. The decorators do not seem to fire properly.

Steps to Reproduce the Problem

I have two example components hosted on a public bit collection, both using MobX.

The first example - https://bit.dev/seaal/test/mobx-test - uses MobX decorators and does not work correctly in the playground or when downloaded as a package.

The second example - https://bit.dev/seaal/test/mobx-test-no-decorator - uses MobX but does not use decorators and works correctly both in the playground and when downloaded as a package.

Basic reproduction steps of how to recreate this issue from scratch are below:

  1. Create a fresh Typescript React app with Create React App - npx create-react-app mobx-test --typescript
  2. Setup bit with the typescript compiler within this new app
  3. Enable decorators to be used within typescript by adding "experimentalDecorators": true to the tsconfig.json
  4. Add the required mobx packages to the project - yarn add mobx mobx-react/npm install mobx mobx-react --save

    1. Create a simple react component that uses MobX decorators.

    2. Export our new component component to bit

    3. Look at the playground for the exported component - values that you would expect to update because of MobX reactions do not update.

    4. Alternatively download the component as a package and use it - it also does not update as expected.

Specifications

  • Bit version: v14.0.4
  • Node version: v10.11.0
  • npm / yarn version: v1.15.2
  • Platform: Windows 10 Pro - 64 Bit
  • Bit compiler (include version): bit/envs/compilers/typescript v0.05
  • Bit tester (include version): N/A

Most helpful comment

@JoshK2 thanks! We'll test it in our upcoming sprint.

All 5 comments

@Seaal Thanks for this, I'll add this to the config and publish a new version of the compiler.
Also, there is another version of the ts compiler I did which also generated the d.ts files as part of the compile process (so the dist folder will have the d.ts files).
I didn't test it enough and the performance is not great but feel free to take a look and try it.
https://bit.dev/bit/envs-dev/compilers/typescript

Also, there is another version of the ts compiler I did which also generated the d.ts files as part of the compile process (so the dist folder will have the d.ts files)

@GiladShoham does that mean that we don't need to manually add the d.ts files to our component?

@fabgallo yes:)

@fabgallo We released a new react-typescript compiler with a new typescript version and better configuration that also supports experimentalDecorators.
For the auto-generate d.ts files you still need to wait, this is in progress.

You can see your components working with the typescript compiler here:
https://bit.dev/joshk/typescript-test1/mobx-test
https://bit.dev/joshk/typescript-test1/mobx-test-no-dec

Link to react-typescript compiler https://bit.dev/bit/envs/compilers/react-typescript

@JoshK2 thanks! We'll test it in our upcoming sprint.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlexanderKaran picture AlexanderKaran  路  22Comments

ranm8 picture ranm8  路  16Comments

poriaz picture poriaz  路  15Comments

JoshK2 picture JoshK2  路  12Comments

AlexanderKaran picture AlexanderKaran  路  10Comments