0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 05:42:36 +08:00
discourse/frontend/discourse-types
Sérgio Saquetim 89679acf21
DEV: Use bundler module resolution for @discourse/types consumers (#41661)
The declarations in `@discourse/types` are emitted by core under
`moduleResolution: bundler`, so their relative re-exports are
extensionless (`truth-helpers/index.d.ts` re-exports `./helpers/or`, no
extension). Plugins and themes extend `tsconfig-plugin.json`, which was
still on `nodenext`; in a `type: module` package nodenext cannot resolve
an extensionless relative re-export, so every symbol reached through a
barrel resolved to `any` for consumers.

`discourse/truth-helpers` is the most visible case (a pure re-export
barrel, imported in hundreds of places), but this affects every barrel
in the shipped declarations.

For example, in a plugin:

```gts
import { gt } from "discourse/truth-helpers";

<template>
  {{! @label is typed as a string; gt returns a boolean }}
  <SomeComponent @label={{gt @count 5}} />
</template>
```

This still builds and runs identically; types are stripped at build, so
there is no runtime change. Only type-checking differs. `gt` returns a
boolean and `@label` expects a string, so this is a type error, but
under `nodenext` it went unreported because `gt` had degraded to `any`.
Under `bundler`, `gt` resolves to its real signature and `pnpm
lint:types` (and the editor) flag it:

```
Type 'boolean' is not assignable to type 'string'.
```

Editor hover and autocomplete are restored, and `or`/`and` recover the
precise return types that motivated backing truth-helpers with the
package.

The fix points consumer resolution at the same mode the declarations are
produced under: `moduleResolution: bundler` and `module`/`target`
`es2022`, matching `tsconfig-base.json`. Core and Embroider already
resolve this way.

Verified by repointing every in-repo plugin and theme at the workspace
`@discourse/types` and running the full `ember-tsc -b` build: it stays
green, with nothing previously masked by `any` surfacing. External
plugins and themes carry no type-checked TypeScript that depends on
nodenext.

Because barrels now resolve to real types, a consumer that type-checks
its own code may surface a pre-existing mistake that `any` was hiding
after it upgrades; that is the intended effect, not a regression.
2026-07-13 21:43:39 -03:00
..
.npmignore
dts-generator.ts
generate-external-types.js DEV: Back truth-helpers with the ember-truth-helpers package (#41621) 2026-07-13 13:06:17 -03:00
package.json DEV: Back truth-helpers with the ember-truth-helpers package (#41621) 2026-07-13 13:06:17 -03:00
process-package-json.js
tsconfig-plugin.json DEV: Use bundler module resolution for @discourse/types consumers (#41661) 2026-07-13 21:43:39 -03:00