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.

How typesafe can a remote be with Typescript?

See original GitHub issue

Update from @ScriptedAlchemy - https://www.npmjs.com/package/@module-federation/typescript has been released

I can see a disadvantage using remotes libraries vs the classical libraries where e.g. typescript can be used to enforce strong types. The current typescript example defines a generic app2/Button which is similar defining a any type.

https://github.com/module-federation/module-federation-examples/blob/cf2d070c7bbb0d5f447cfe33f69e07bcf85f8ddb/typescript/app1/src/app2.d.ts#L3-L7

As the remote var does not have type, I don’t see a way to benefit from the app2 types in app1. Any idea on this?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:50
  • Comments:82 (24 by maintainers)

github_iconTop GitHub Comments

30reactions
ScriptedAlchemycommented, May 20, 2020

ill raise this with Microsoft - they will have to support federation since they are going to be using it heavily

28reactions
maraisrcommented, May 8, 2020

What I have done is use node to generate a .d.ts file, that are loaded by our global.d.ts file.

So each Remote outputs a .d.ts file that go declare module "dlaWidgets/Widets" {}, with using the ts.createProgram you can tap into the typeChecker stuff that i use to print its public api. Kinda like getting tsc to ouput definition files, but instead spit them into a single file.

Then each of my hosts import this .d.ts file, which I have registered in a global.d.ts, that all of my projectReferenced monorepo apps include.

So there is a small disconnect between a webpack config, and the types. But any exposed things, are automagically available with types in my entire app. So ts might say its a valid import, but just need to actially configure it with webpack also.

Working on open sourcing this generative thing - just gotta make sure it works in all use cases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript Types for Federated Modules and Microfrontends
Microfrontends aren't the only thing you can use module federation for, but it's certainly ... How typesafe can a remote be with Typescript?...
Read more >
How to keep types while using module federation? | by Josh Lin
How typesafe can a remote be with Typescript ? May 5… github.com. That is a good question, let's break it down first. module...
Read more >
Translating API responses into type-safe interfaces with ...
Translating API responses into type-safe interfaces with TypeScript ... HTTP APIs using JSON as a data exchange format are characterized by a ...
Read more >
Type safe client-side queries in TypeScript - ITNEXT
Since we want our queries to support looking up fields from a remote source, we could add a with_field method. This method will...
Read more >
Building an end-to-end typesafe API — without GraphQL
As TypeScript approaches near-universal adoption in the JS ecosystem, that means most GraphQL-based projects will soon be TypeScript-based ...
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