[ZEPPELIN-6447] Add Module Federation typing for the published paragr…#5343
[ZEPPELIN-6447] Add Module Federation typing for the published paragr…#5343JangAyeon wants to merge 1 commit into
Conversation
…aph React container Reuses the RemoteContainer type already declared by ReactRemoteLoaderService (ZEPPELIN-6428) for window.reactApp, removing the @ts-ignore in PublishedParagraphComponent.loadReactWidget() so the container's get() call is type-checked instead of suppressed.
There was a problem hiding this comment.
tsc passes locally, so removing the @ts-ignore works.
One thing that isn't obvious from the issue: the type declaration ZEPPELIN-6447 asks for already exists. 52a638e (ZEPPELIN-6428, Jun 17) added a declare global block at react-remote-loader.service.ts:22 declaring Window.reactApp as RemoteContainer | undefined, and it applies program-wide. The issue was filed on Jun 27, so criterion 2 ("the container type includes at least the get API") was already satisfied by the time it was written, and the @ts-ignore was the only part left.
Which means the import and the export don't add any typing. I reverted the import, the annotation and the export and ran tsc again, and the output was the same (exit 0, nothing printed). To rule out the type having fallen back to any I added container?.nope() with no import, and it still errored with TS2339: Property 'nope' does not exist on type 'RemoteContainer'.
Either way works, just flagging it.
What is this PR for?
PublishedParagraphComponent.loadReactWidget()read the global Module Federation container viawindow.reactAppbehind a@ts-ignorecomment, so the compiler couldn't check thecontainer.get(...)call that follows it.ReactRemoteLoaderServicealready declares this container's shape asRemoteContainerand augmentsWindow.reactAppwith it globally. This PR exports that existing interface and reuses it here instead of adding a second, possibly conflictingWindow.reactApptyping.What type of PR is it?
Improvement
Todos
@ts-ignorecomment nearwindow.reactAppRemoteContainerinterface (covers thegetAPI used here)window.reactApp not availableerror when the container is missingWhat is the Jira issue?
ZEPPELIN-6447
How should this be tested?
cd zeppelin-web-angular && npm run lintpasses with no new errors.?react=trueand confirm the React widget still mounts; without the remote entry script, the "window.reactApp not available" error still surfaces.Questions: