Implement type/namespace duality & export constant values to library consumers #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
resolves #16 & #15, supersedes #17
this PR contains no breaking changes, but adds
types &namespaces where possible to shortcut the use of.Value, &.VALUE, as well as compiles a.jsfile containing all the constants in the project asnamespaceenums, so consumers can use them in their projects without disablingisolatedModules.this is achieved using "type duality", basically using the same name for a
type&const/namespace. in practice, the following pattern is common:however, there are a few caveats when it comes to backwards compatibility:
const enums (i.e..VALUE) to use the same pattern as above. this enables exporting them into the JavaScript world (rather than only via the TypeScript compiler), as well as enables us to reference one single source of truth in the source code when performing compat work (rather than being required to duplicate the literal)const enums, as well asnamespacetop-leveltypedeclarations ofenumvalues (e.g.TextType.Regular→TextType.Caps.Regular). i strongly recommend we keep this deprecation, because this compat code introduces a lot of noise in the codebase.a few extra notes that were done in this PR are:
bundlersetting formoduleResolution. it is required to compile in extension-agnostic mode forimportpaths (e.g.import a from './a';). whilst this setting does come with its own caveats when used in a library, we are bundling our entry points so those don't concern us.do let me know if this is inline with the goals of the project & if there are any further changes that can be considered to ease merging of this PR. thanks!