question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Seeking Help] Adding Typescript Support

See original GitHub issue

Hey All! I’m not a TS expert, yet many people in the community are asking for TS support. That said, I’d love the help from someone who knows TS and common TS toolchains to help us get native TS support in Elder.js.

Hurdles Blocking TS Support

At a high level the main hurdle to implementing TS for Elder.js really comes down to:

The fact that there are several files that read the system expects .js files in specific places. These files include:

  1. routes.ts
  2. externalHelpers.ts
  3. plugins.ts
  4. rollupPlugin.ts (look for ./server.js)
  5. I’m sure there are more… (I’ll update this list with edits)

When Should Elder.js Compile TS?

Accepting TS files in the above listed code isn’t a hard problem to solve, there was a partial attempt to get these playing nicely which you can see on this PR (https://github.com/Elderjs/elderjs/pull/170)… the main problem comes down to when we compile TS and run that code.

The way I understand it there are two options:

  1. Update the Elder.js srcDir to match the outDir found in the tsconfig and update all of the files Elder.js reads looking for .js and allow it to accept .ts as well. This would be done in getConfigand let the user handle the compilation in their own tool chain. I planned on using this approach in alpha versions of Elder.js.

  2. Another suggestion from @orta that is on the TS team mentioned that we could just use an esbuild background process to transpile TS on the fly and just run the output as if it was a JS file.

The main reason neither of these have been implemented is that I just don’t understand TS tooling well enough to make a decision because I don’t know the pros/cons of each.

If anyone has strong opinions or would like to offer support, I’m all ears. 👂 👂 👂

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tylerjlawsoncommented, Sep 19, 2021
const jsversion = esbuild.transformSync(fs.readFileSync("routes.js"), { loader: 'ts' })

@orta should this code say routes.ts?

0reactions
AcrylicShrimpcommented, Nov 29, 2022

Thank you for your hard working! I’m very sorry for spamming, but is there any progress on this? It would be great if we can use Typescript for Elder.js.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add TypeScript support to an existing codebase | by Billel
Install typescript npm package and node type definitions. Just run npm i --save-dev typescript @types/node; Create a file named tsconfig.json at the route...
Read more >
How to set up TypeScript
To do this, run npm install -g typescript . This will install the latest version (currently 4.9).
Read more >
How to Add TypeScript to a JavaScript Project - freeCodeCamp
The first way involves using declaration files. A simple addition of d.ts files helps the TS compiler type-check existing JavaScript code and ...
Read more >
Adding TypeScript - Create React App
Global installs of create-react-app are no longer supported. To add TypeScript to an existing Create React App project, first install it:.
Read more >
How to Set Up a Node.js Project with TypeScript
To add TypeScript support to ESLint, install the @typescript-eslint/parser and @typescript-eslint/eslint-plugin packages in your project. The ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found