I have been trying to create HTML documentation for my TypeScript project using Typedoc.
Within one of the many files, there is a snippet of code:
public doSomething(val: number | undefined | null | string): string | undefined | null {
if (val === null || val === undefined || typeof val === 'string') {
return val;
}
...
While WebStorm does not show any errors and indicates that val
in the return
statement is of type string | null | undefined
, Typedoc encounters an issue during compilation. The error thrown states:
TS2322: Type 'string | number' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
This discrepancy between Typedoc's analysis and the actual behavior of the application when run with nx serve
raises questions about how Typedoc processes type assertions. How can I address this issue and ensure consistency across our development environment?
Although I could make changes to this specific section of code, relying on Typedoc without ensuring compatibility across our team poses challenges given our large group of developers.
UPDATE: Despite setting the module's target to es2020
initially, switching to es2022
did not resolve the Typedoc compilation error or impact the nx serve
build process.
Interestingly, copying and pasting the same function elsewhere in the codebase allows Typedoc to compile it without issues. While a local typedoc.config.json
file exists, it only references the main configuration file and specifies local entry points.