tsdx icon indicating copy to clipboard operation
tsdx copied to clipboard

Refactor/Improve some typings

Open agilgur5 opened this issue 5 years ago • 1 comments

Description

Commits

types: add remaining external typings

  • added @types/babel__core, @types/babel__traverse, and @types/lodash.merge and removed their declarations in env.d.ts

    • also removed rollup-plugin-terser's declaration there because it has types built-in
    • remaining actually don't have types per in-line comments
  • this improved type-checking allowed TS to do stricter checks and so exposed a few type errors that were fixed as well

    • @rollup/plugin-babel depends on @types/babel__core as well, so the declaration here had previously overridden it
      • custom had to be augmented as it's not an option of @rollup/plugin-babel
      • passPerPreset did too though... it's not in @types/babel__core but it is a (deprecated) Babel option
        • logs seemed to show it was false regardless of what was passed in though...
    • Rollup's plugins now started complaining that false wasn't a valid Plugin either, so added a .filter(Boolean) but that didn't fully fix it so had to type-cast

refactor/fix: consistently use capital TSDX everywhere

  • Jared had asked in a review comment back in December to consistently use capital TSDX (not tsdx) so this establishes that throughout the rest of the codebase

    • I don't think any of these lines/files/variables were written by me, so I'm just fixing up existing ones
  • this came up as I was refactoring typings, so wanted to make sure everything was consistent as I went

refactor/types: explicitly name "at least one" types

refactor/types: add a type for RollupOptionsWithOutput

refactor/types: add a TSDXConfig type

  • another PR by a contributor exposes the types for tsdx.config.js in order to be used in JSDoc, so this makes it so only a single type is needed and exported

Tags

  • Using capital TSDX instead of tsdx, "tsdx", etc was requested in https://github.com/formium/tsdx/pull/400#discussion_r361858698. Maybe in an earlier issue/PR too, but I couldn't find or remember it.
  • The "at least one" type confusion was in https://github.com/formium/tsdx/pull/401#discussion_r361774071
  • TSDXConfig type is pretty much just to simplify #823

Review Notes

The passPerPreset augmentation for @rollup/plugin-babel / @types/babel__core that is mentioned above is pretty confusing. I decided to leave it as is for now so as to potentially change anything, but my logs seem to show it isn't used 😕 🤔 :

Babel log output:
PartialConfig {
  options:
   { sourceMaps: true,
     caller:
      { name: '@rollup/plugin-babel',
        supportsStaticESM: true,
        supportsDynamicImport: true,
        supportsTopLevelAwait: true },
     filename:
      '[redacted]/tsdx/stage-build-default/src/syntax/jsx-import/JSX-B.jsx',
     babelrc: false,
     configFile: false,
     passPerPreset: false,
     envName: 'test',
     cwd:
      '[redacted]/tsdx/stage-build-default',
     root:
      '[redacted]/tsdx/stage-build-default',
     plugins: [],
     presets: [] },
  babelignore: undefined,
  babelrc: undefined,
  config: undefined }
{ sourceMaps: true,
  caller:
   { name: '@rollup/plugin-babel',
     supportsStaticESM: true,
     supportsDynamicImport: true,
     supportsTopLevelAwait: true },
  filename:
   '[redacted]/tsdx/stage-build-default/src/syntax/jsx-import/JSX-B.jsx',
  babelrc: false,
  configFile: false,
  passPerPreset: false,
  envName: 'test',
  cwd:
   '[redacted]/tsdx/stage-build-default',
  root:
   '[redacted]/tsdx/stage-build-default',
  plugins:
   [ ConfigItem {
       value: [Function],
       options: {},
       dirname:
        '[redacted]/tsdx/stage-build-default',
       name: undefined,
       file: [Object] },
     ConfigItem {
       value: [Function: _default],
       options: {},
       dirname:
        '[redacted]/tsdx/stage-build-default',
       name: undefined,
       file: [Object] },
     ConfigItem {
       value: [Function],
       options: {},
       dirname:
        '[redacted]/tsdx/stage-build-default',
       name: undefined,
       file: [Object] },
     ConfigItem {
       value: [Function],
       options: [Object],
       dirname:
        '[redacted]/tsdx/stage-build-default',
       name: undefined,
       file: [Object] },
     ConfigItem {
       value: [Function],
       options: [Object],
       dirname:
        '[redacted]/tsdx/stage-build-default',
       name: undefined,
       file: [Object] } ],
  presets:
   [ ConfigItem {
       value: [Function],
       options: [Object],
       dirname:
        '[redacted]/tsdx/stage-build-default',
       name: undefined,
       file: [Object] } ] }
PartialConfig {
  options:
   { sourceMaps: true,
     caller:
      { name: '@rollup/plugin-babel',
        supportsStaticESM: true,
        supportsDynamicImport: true,
        supportsTopLevelAwait: true },
     filename:
      '[redacted]/tsdx/stage-build-default/src/syntax/jsx-import/JSX-B.jsx',
     babelrc: false,
     configFile: false,
     passPerPreset: false,
     envName: 'test',
     cwd:
      '[redacted]/tsdx/stage-build-default',
     root:
      '[redacted]/tsdx/stage-build-default',
     plugins: [],
     presets: [] },
  babelignore: undefined,
  babelrc: undefined,
  config: undefined }

Misc

This will be rebased in as each commit is independent and some have some lengthy messages.

agilgur5 avatar Oct 20 '20 03:10 agilgur5

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/formium/tsdx/nrywlnc8b
✅ Preview: https://tsdx-git-typings-refactor.formium.vercel.app

vercel[bot] avatar Oct 20 '20 03:10 vercel[bot]