Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.

Treat namespace and class exports differently#19

Merged
alloy merged 19 commits into
mainfrom
stash-default-class-typeof
Jan 28, 2021
Merged

Treat namespace and class exports differently#19
alloy merged 19 commits into
mainfrom
stash-default-class-typeof

Conversation

@alloy

@alloy alloy commented Jan 28, 2021

Copy link
Copy Markdown
Member
  • Removes automated namespace generation, because the one big usage of it that we have also requires the ability to extend the namespace in a different module and TS does not allow that. The only solution I could come up with was to add overrides that do the exact thing needed, which in this case is to re-export all ES6 exports (of AnimatedMock) and then capture all those ES6 exports (from Animated) as a namespace when importing.
  • Removes the $TypeOf helper

@alloy alloy self-assigned this Jan 28, 2021
declare const $f2d_unforkEvent: typeof $3.unforkEvent;
declare const $f2d_Event: typeof $1.AnimatedEvent;
declare const $f2d___PropsOnlyForTests: typeof $6;
export { $f2d_Value as Value, $f2d_ValueXY as ValueXY, $f2d_Interpolation as Interpolation, $f2d_Node as Node, decay, timing, spring, $f2d_add as add, $f2d_subtract as subtract, $f2d_divide as divide, $f2d_multiply as multiply, $f2d_modulo as modulo, $f2d_diffClamp as diffClamp, delay, sequence, parallel, stagger, loop, event, $f2d_createAnimatedComponent as createAnimatedComponent, $f2d_attachNativeEvent as attachNativeEvent, $f2d_forkEvent as forkEvent, $f2d_unforkEvent as unforkEvent, $f2d_Event as Event, $f2d___PropsOnlyForTests as __PropsOnlyForTests };

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. So now we just export all the fields on the exported object as individual ES6 exports…

@@ -1,4 +1,4 @@
import { $TypeOf } from "flow2dts-flow-types-polyfill";
export * from "./AnimatedMock";

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. …then we re-export all those ES6 exports here…

import AnimatedView$f2tTypeof from "./components/AnimatedView";
declare type AnimatedView = typeof AnimatedView$f2tTypeof;
import $1 from "./AnimatedMock";
export { AnimatedFlatList$f2tTypeof as FlatList, AnimatedImage$f2tTypeof as Image, AnimatedScrollView$f2tTypeof as ScrollView, AnimatedSectionList$f2tTypeof as SectionList, AnimatedText$f2tTypeof as Text, AnimatedView$f2tTypeof as View };

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. …and add a few more ES6 exports, thus ‘extending’ the exports of ./AnimatedMock

import Alert$f2tTypeof from "./Libraries/Alert/Alert";
declare type Alert = typeof Alert$f2tTypeof;
import Animated$f2tTypeof from "./Libraries/Animated/Animated";
import * as Animated$f2tTypeof from "./Libraries/Animated/Animated";

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. …and finally we capture all those ES6 exports as a namespace, which is then exported to the consumer.

@alloy alloy merged commit 33fc656 into main Jan 28, 2021
@alloy alloy deleted the stash-default-class-typeof branch January 28, 2021 14:04
if (path.findParent((parentPath) => parentPath.isDeclareModuleExports())) {
// it's a class on `module.exports`, leave `typeof` for the `exportVisitor`
return
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the one change I had to make when hints are enabled.

@alloy alloy mentioned this pull request Jun 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant