Commit 79f4cc7
fix: fixes importMap type in monorepo usage (#15203)
### What?
Adds a `/** @type import("payload").ImportMap */` annotation to the
generated importMap.
### Why?
In a monorepo, it's common to use [Project
References](https://www.typescriptlang.org/docs/handbook/project-references.html)
so that Typescript can do dependency analysis on the packages in your
project. Often, projects will have a single root `tsconfig.json` that
`references` all of the packages, including any apps. To do so, all
dependent `tsconfig.json`s must set `"composite": true`.
When `"composite": true` is set in a package, Typescript does
portability analysis on all exports to ensure that Typescript will be
able to properly determine the type of those exports if they are
imported into a consuming package as a dependency. This is true even if
that package never ultimately exports that type through its `main` or
`exports` fields, or is private, or is not depended on by any other
projects. This portability check happens _even if checkJs is disabled_.
Because `importMap` relies on type inference on transient dependencies,
Typescript requires a type annotation to conclude that its type is
portable.
Ultimately, there's no reason for Payload consumers to care about or
enforce the type of `importMap`. It's automatically generated by
Payload, never hand edited, and only consumed by other auto-generated
Payload code.
Since Payload already has a type for `ImportMap`, we can type
`importMap` with that type. It will satisfy the type, and is also
considered portable.
### How?
Updated the generateImportMap template.
Fixes #9914
Co-authored-by: Paul Popus <paul@payloadcms.com>1 parent b3d2054 commit 79f4cc7
1 file changed
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
| |||
0 commit comments