Skip to content

Conversation

@ansemb
Copy link
Member

@ansemb ansemb commented Aug 11, 2025

Problem

The d.ts emitter failed when re-exporting a specialized EventingInterceptor.

For:

import type { events as cardEvents } from "@repo/react-component-nova-events";
import {
  EventingInterceptor as GenericEventingInterceptor,
  type EventingInterceptorFn,
} from "nova-react-test-utils";

export const EventingInterceptor =
  GenericEventingInterceptor<
    typeof cardEvents
  >;

It’s a .d.ts–emitter issue. Where exporting a value whose inferred
type, after we specialize the generic with typeof cardEvents, ends up
mentioning types that TypeScript can only refer to via a non‑portable path like
../../../../<package>/node_modules/@nova/types/lib. When TS tries to print
your package’s .d.ts, it can’t name that type with a stable module specifier, so
it asks you to add an explicit, portable annotation.

We get the error:

> The inferred type of 'EventingInterceptor' cannot be named without a reference to
`../../../../<package>/node_modules/@nova/types/lib`.
This is likely not portable. A type annotation is necessary.

This error often appears when a type is only reachable through a transitive package's node_modules.

Solution

  • Added a public generic type:
export type EventingInterceptorFn<T extends EventCreatorMap> =
  (props: EventingInterceptorProps<T>) => React.ReactElement;

So we get a monomorphic type when used like:

export const EventingInterceptor: EventingInterceptorFn<typeof cardEvents> =
  GenericEventingInterceptor

@sjwilczynski sjwilczynski merged commit 1f4b28f into microsoft:main Aug 12, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants