lwc icon indicating copy to clipboard operation
lwc copied to clipboard

Add TypeScript support to LWC authoring format

Open AllanOricil opened this issue 3 years ago • 5 comments

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like Add typescript support

Describe alternatives you've considered NA

Additional context The industry of frontend frameworks are going towards Typescript, Thinking on that, will LWC support typescript in the near future?

AllanOricil avatar Nov 06 '20 13:11 AllanOricil

+1 I would love TypeScript support, but I can understand how this might be difficult on the platform because of the non-standard import scheme used before compilation.

eight-molecules avatar Nov 09 '20 19:11 eight-molecules

For the record, LWC does allow Typescript, here is an example (it might be a bit outdated but will be good enough for making the point): https://github.com/diervo/lwc-typescript-boilerplate

In a nutshell you just need to remove the types before running LWC compiler.

As for the platform usage: We will never be able to natively support Typescript (meaning we won't be able to ever allow you to save components in original .ts format) fundamentally due to the fact that typescript can have breaking changes from version to version, which means that we will have to support N+1 versions of platform until the ends of time, which is something we can't afford to do.

We do want to provide types and tooling to make it as seamless as possible, so all developers can choose to use Typescript from a "practically full" e2e development in platform.

diervo avatar Nov 09 '20 20:11 diervo

@diervo thank you. I googled it and could not find anywhere. It would be cool if we could develop using typescript, and during the push command sfdx would build the lwc source to javascript before saving the components on the org. This could be an sfdx extension but it would be necessary to have all the Types defined. Wouldn't it work?

AllanOricil avatar Nov 09 '20 21:11 AllanOricil

Yes, that's the goal. I would suggest you create an item in the IdeaExchange https://trailblazer.salesforce.com/ideaSearch (if there is not one already) and get a lot of people voting it up so it gets prioritize accordingly since the LWC team does not own the DX integration.

diervo avatar Nov 09 '20 22:11 diervo

Even if LWC on platform doesn't "natively" run TypeScript, tooling could make it a near-native solution:

  • tooling to retrieve type files for sObjects and LWC APIs (and do so automagically when working in VC Code)
  • tooling to transpile LWC to JS when deploying to an org, and ideally to also preserve source-mapping upon deployment (perhaps only when a debug flag is enabled)

Here's the most applicable idea to upvote: https://ideas.salesforce.com/s/idea/a0B8W00000GdZyWUAV/enable-lightning-component-developers-to-use-typescript-and-ecmascript-6

timothywlewis avatar Mar 04 '22 19:03 timothywlewis

This is still planned

nolanlawson avatar May 18 '23 20:05 nolanlawson