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

TypeScript support #197

Closed
zamotany opened this issue Jan 26, 2018 · 25 comments
Closed

TypeScript support #197

zamotany opened this issue Jan 26, 2018 · 25 comments
Labels
enhancement: proposal 💬 Improvement of current behaviour that needs to be discussed needs: help 🆘 Help is needed

Comments

@zamotany
Copy link
Contributor

No description provided.

@zamotany zamotany added enhancement: proposal 💬 Improvement of current behaviour that needs to be discussed needs: help 🆘 Help is needed labels Jan 26, 2018
@dumaron
Copy link

dumaron commented Feb 22, 2018

Hi, any news on this?
Can you tell me what need to be done in order to help?

@thymikee
Copy link
Member

To make that happen we'll need to migrate to Babel 7 and make sure all works with @babel/preset-typescript

@dumaron
Copy link

dumaron commented Feb 22, 2018

This, however, will not help the ones working on projects bootstrapped with create-react-app-typescript, right? This will only support typescript if transpiled from babel?

@thymikee
Copy link
Member

No, it won't work. Linaria is a Babel preset. AFAIK TypeScript doesn't allow you to transform its AST like Babel does. However, with Babel 7 you should be able to technically pre-compile your app (typescript and linaria presets required) before it goes to tsc.

@MartinJohns
Copy link

AFAIK TypeScript doesn't allow you to transform its AST like Babel does.

TypeScript has support for transformers: microsoft/TypeScript#13764

@resir014
Copy link

To make that happen we'll need to migrate to Babel 7 and make sure all works with @babel/preset-typescript

Not only that, but a type declaration (.d.ts) also needs to be provided.

@satya164
Copy link
Member

cc @Esemesek, our ts hero

satya164 added a commit that referenced this issue Oct 17, 2018
satya164 added a commit that referenced this issue Oct 17, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 18, 2018
satya164 added a commit that referenced this issue Oct 19, 2018
satya164 added a commit that referenced this issue Oct 19, 2018
@satya164
Copy link
Member

@resir014 can you check #263 if it helps?

@resir014
Copy link

resir014 commented Oct 19, 2018 via email

@satya164
Copy link
Member

Can this be closed? We now use Babel 7 and also ship TypeScript definitions.

zamotany pushed a commit that referenced this issue Nov 25, 2018
@zamotany
Copy link
Contributor Author

For TS support: you need to use babel 7 with typescript preset.

@ShanonJackson
Copy link

Fucking around with linaria on weekends in preparation for when we stop supporting IE11 in production and i can swap from styled-components. Making sure the SSR all works etc etc i'm finding the lack of documentation for typescript support basically null, after reading the documentation it's starting to look like i'm literally forced to stop using awesome-typescript-loader (in dev) and ts-loader (in prod build for multi-threading with happypack which comes in slightly faster than ATL), just to use linaria and instead reconfigure my entire application to use babel.

Is there a workaround where i can configure the SSR to work without using babel and not get the "Error using the "styled" tag in runtime is not supported....."

@zamotany
Copy link
Contributor Author

zamotany commented May 6, 2019

Unfortunately no, TypeScript compiler do not provide public API for writing custom transformers, so we cannot support tsc. Currently, there's no way to use linaria without babel.

@steadicat
Copy link

FWIW, here's the issue that tracks adding support for custom transformers to the TypeScript compiler: microsoft/TypeScript#14419

@ShanonJackson
Copy link

@zamotany Anychance in the intermediatory period we could have some cool babel cats out there setup a typescript example setup of both frontend / backend Typescript + Babel + Linaria? Spent about 8 hours now trying to configure something that will work but as someone with little babel experience (and someone who finds the babel documentation and plugin system confusing) it would be great to have an example template which shows the two running together.

(Backend with Linaria/Typescript/Babel for SSR).

@geakstr
Copy link
Contributor

geakstr commented Jun 14, 2019

Hi and thanks for linaria! In our project we use typescript namespaces, so we can't move to @babel/preset-typescript (it doesn't support namespaces). It would be really cool to have linaria worked with ts-loader. Is there any chance?

@chrisabrams
Copy link
Contributor

@geakstr have you tried running babel in front of ts-loader?

@geakstr
Copy link
Contributor

geakstr commented Jun 24, 2019

@chrisabrams yes, from webpack config:

{
  test: /\.(ts|tsx)$/,
  include: paths.appSrc,
  use: [
    {
      loader: require.resolve("babel-loader")
    },
    {
      loader: require.resolve("linaria/loader"),
      options: {
        sourceMap: process.env.NODE_ENV !== "production"
      }
    },
    {
      loader: require.resolve("ts-loader"),
      options: {
        // disable type checker - we will use it in fork plugin
        transpileOnly: true,
        experimentalWatchApi: true
      }
    }
  ]
}
...
{
  test: /\.s(c|a)ss$/,
  use: [
    {
      loader: MiniCssExtractPlugin.loader,
      options: {
        hmr: process.env.NODE_ENV !== "production"
      }
    },
    {
      loader: require.resolve("css-loader"),
      options: {
        importLoaders: 2,
        sourceMap: true,
        modules: {
          mode: "local",
          localIdentName: "[name]_[local]_[hash:base64:5]"
        }
      }
    },
    {
      loader: require.resolve("postcss-loader"),
      options: {
        sourceMap: true,
        // Necessary for external CSS imports to work
        // https://github.com/facebookincubator/create-react-app/issues/2677
        ident: "postcss",
        plugins: () => [
          require("postcss-flexbugs-fixes"),
          autoprefixer({
            flexbox: "no-2009"
          })
        ]
      }
    },
    {
      loader: require.resolve("sass-loader"),
      options: {
        sourceMap: true
      }
    }
  ]
}

.babelrc

{
  "presets": ["@babel/preset-env", "@babel/preset-react", "linaria/babel"]
}

In runtime: Error: Using the "css" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly.

@geakstr
Copy link
Contributor

geakstr commented Jun 24, 2019

Wow, got it work! The problem was "module": "commonjs"/"target": "es5" in tsconfig.json. With this config linaria/loader gets already transpiled imports. Changed to "module": "esnext"/"target": "esnext" - all works fine. It is super unintuitive and it should be reflected somewhere in the docs. Let me prepare PR when I have a chance.

@BasixKOR
Copy link

BasixKOR commented Jan 3, 2020

Hi, It seems like ts-loader supports custom transformer using their API. Can we use ts-loader instead of babel-loader with this API?

Related documentation: https://github.com/TypeStrong/ts-loader#getcustomtransformers

@Jack-Works
Copy link
Contributor

Hello, this project looks awesome but it requires Babel... I have rich experience in writing TypeScript transformers, for example react-refresh-typescript to the official react-refresh/babel transformer.

I'd like to write a TypeScript version so I (and other people) can use this project with ts-loader. But if I made that, will this project accept the PR?

@Anber
Copy link
Collaborator

Anber commented Apr 16, 2021

Hi @Jack-Works

We will. But I bet that it wouldn't be simple :)

@Anber
Copy link
Collaborator

Anber commented Apr 17, 2021

@Jack-Works If you really want to try, you can create an issue and I will help you with planning and implementation, because such a task requires a few new abstractions in our existing code base.

@Jack-Works
Copy link
Contributor

I'd like to introduce jest-file-snapshot and let test cases become a folder on their own (so I can share the test with TypeScript after I start coding).

An example in my project:
test files in a folder
snapshot for TypeScript transformer
test file that read those test files for TypeScript transformers

Is this ok? @Anber

@Anber
Copy link
Collaborator

Anber commented Apr 25, 2021

Sounds good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement: proposal 💬 Improvement of current behaviour that needs to be discussed needs: help 🆘 Help is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.