Page MenuHomePhabricator

Type definitions import from packages that aren't listed as dependencies
Closed, DuplicatePublic

Description

Right now, the generated TypeScript type definitions for @wikimedia/codex refer to the Icon type, which they import from @wikimedia/codex-icons. However, the @wikimedia/codex package doesn't declare a dependency on @wikimedia/codex-icons, because it doesn't depend on that package at runtime; only the type definitions do. This causes errors for end users using TypeScript, unless they install both packages.

Similarly, with the approach proposed in https://gerrit.wikimedia.org/r/c/design/codex/+/769811 , the new @wikimedia/codex-search package would import all of its type definitions from @wikimedia/codex, but it doesn't formally depend on that package.

I see two possible approaches to solve this problem:

  1. Add @wikimedia/codex-icons as an NPM dependency of @wikimedia/codex. That's a little misleading, because it's not an actual runtime dependency (the components use some icons, but they embed them rather than getting them from the icons package at runtime), but it would be a simple way to fix the TypeScript issue.
  2. Find a way to make TypeScript embed imported declarations. This seems to be difficult to do, and consolidating all the type definitions from a package into a single file would probably be a step in that direction, but that also seems to be difficult.

Perhaps we should do #1 for now, and then consider trying #2 later?

Event Timeline

Perhaps add a separate @wikimedia/codex-types package that is shared between multiple packages?

Any typescript type that needs to be available in multiple packages should be defined in the @wikimedia/codex-types package and imported where needed

and then have everything depend on that? Though I'm not very familiar with typescript types so I don't know that this would work

I support investigating clever ways to import/embed type definitions, but I know that can be a bit of a rabbit hole.

I am fine with option #1 for now – a dependency on a type from another package is still a dependency (maybe a devDependency if we're going to be precise).