Skip to content

maint(common): consider declaring used types/libs in each tsconfig.json #16535

Description

@mcdurdin

For most of our projects, tsc will implicitly include all node_modules/@types type modules in the build. This can cause problems when some of the types depend on e.g. dom. I found this happening when I installed @types/jquery and @types/jqueryui into a Developer project (see #16520). This caused other projects in web such as predictive-text/wordbreakers to fail to build with a string of nearly 100 errors, e.g.:

../../../../../node_modules/@types/jquery/index.d.ts(165,29): error TS2304: Cannot find name 'XMLHttpRequest'.
../../../../../node_modules/@types/jquery/index.d.ts(537,20): error TS2304: Cannot find name 'Element'.
...

A resolution for this may be to explicitly declare the list of types imported with the "types" compiler option. Alternatively, if we want to avoid any implicit import of types for a given module, we could override the "typeRoots" option with "typeRoots": [].

Benefits:

  • Being explicit about our types helps us to avoid accidentally importing node and/or dom types in modules that should not depend on them.
  • We clearly audit our es-version compatibility because we'll need to specify the minimum es version in lib, e.g. "lib": ["es2016"]
  • Setting types and/or typeRoots appears to improve build performance because tsc will no longer load all the myriad @types/.../index.d.ts files unless they are actually referenced. I haven't profiled this yet.

Other thoughts:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    common/maintMaintenance work -- continuous integration, build scripts, infrastructure

    Type

    Projects

    • Status
      Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions