CleverCloud / clever-components

Collection of Web Components by Clever Cloud
https://www.clever-cloud.com/doc/clever-components/
Apache License 2.0
215 stars 19 forks source link

TypeChecking (CI): issue with 3rd party libraries #972

Closed florian-sanders-cc closed 4 months ago

florian-sanders-cc commented 4 months ago

Context

With the latest Storybook upgrade (7.0, see #952), it looks like CI TypeChecking is broken.

What's going on?

  1. The TypeChecker scans d.ts files from the node_modules/@types folder (see https://www.typescriptlang.org/tsconfig#types),
  2. It detects errors related to express, react, trusted_types & babel (see Screenshot below).

image

We cannot solve these errors sicne they are related to 3rd party libraries imported by Storybook.

The typical solution

Usually, people set skipLibCheck to true. This improves performances and prevents 3rd party libraries from making your compilation / typechecking fail.

Unfortunately, this also means our own d.ts files are no longer typechecked. Since we actually hand-author these d.ts files, we think it's critical they are typechecked like the rest of our code.

What we'd like

We would like to be able to exclude the offending types from our typechecking. Unfortunately, this does not seem to be possible at the moment (https://github.com/microsoft/TypeScript/issues/30511) because we're in a case that is not officially supported by TypeScript:

Currently, we have a fairly coherent posture that .d.ts files are either outputs or they describe the shape of colocated JS (as in libraries), but they’re not inputs to be hand-authored.

What can we do?

Instead of excluding the types, we can declare types we want to be included thanks to the types option (see https://www.typescriptlang.org/tsconfig#types). This is cumbersome because we need to manually add types.

At the moment, we only typecheck the src/lib/utils.js file and it looks like the only type we need to import is node so we'll go with that.

We will gradually add types to the list as we need them and if it starts to become painful to maintain, we might need to consider another option, perhaps even the skiLibCheck: true solution.

EDIT: we had to go with skipLibCheck because the solution with the types option failed when upgrading some of our dependencies. One of our dependencies is bringing ts4.8 types in node types and this node lib cannot be checked with our current TypeScript version (~4.3.2).