Skip to content

fix(types): restore missing type exports (#4139) - #4346

Open
RobJacobson wants to merge 1 commit into
rnmapbox:mainfrom
RobJacobson:codex/fix-4139-type-exports
Open

RobJacobson wants to merge 1 commit into
rnmapbox:mainfrom
RobJacobson:codex/fix-4139-type-exports

Conversation

@RobJacobson

Copy link
Copy Markdown
Contributor

Description

Fixes #4139.

Restore the four reported source-path type imports and expose the missing types directly from @rnmapbox/maps:

import type { Expression, SymbolLayerProps, OnPressEvent } from '@rnmapbox/maps';

Existing style aliases remain available.

Root cause

The packaging update for 10.2 introduced a package.json export map without entries for the previously accessible source paths. TypeScript’s bundler resolution respects that map, so the imports fail even though the source files are packaged.

The public entry point also omitted types such as Expression, FilterExpression, symbol-layer props, map payloads, and OnPressEvent, leaving consumers without equivalent public imports.

This change adds explicit declaration exports for only:

  • src/utils/MapboxStyles
  • src/components/SymbolLayer
  • src/components/MapView
  • src/types/OnPressEvent

It also re-exports the missing types through the native public entry point.

No runtime export targets are added. Node rejects runtime imports through these four paths. Metro retains its warning and source-file fallback behavior; this was verified separately.

Before and after verification

The strengthened regression suite was run against the unfixed base (42758736) and the fixed implementation. It builds JavaScript and declarations with the repository’s real build targets, packs them with Yarn, and checks the extracted package.

Check Unfixed base Fixed implementation
Reported source imports Four unresolved-module errors All resolve
Missing public type imports Missing-export errors All resolve
Packaged regression suite Three failures, six passes Nine passes

The suite checks:

  • Public and legacy imports with moduleSuffixes: [""] and [".native", ""].
  • Compatibility between public types, legacy types, and existing aliases.
  • Generated ESM package metadata and packaged export targets.
  • React and GeoJSON dependencies, including rejection of invalid type usage.
  • Unrelated internal source paths remain unavailable through TypeScript package exports.
  • Real Node resolution rejects runtime imports through the compatibility paths.

Additional verification:

  • yarn test: 26 suites and 173 tests passed; lint completed with warnings and no errors.
  • Library source type checking passed with generated lib/ output excluded.
  • Example source type checking passed.
  • yarn generate passed; no generated-file changes.
  • Metro resolved SymbolLayer.tsx with its expected fallback warning.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder
  • I have tested the new feature on /example app.
    • In V11 mode/ios
    • In New Architecture mode/ios
    • In V11 mode/android
    • In New Architecture mode/android
  • I added/updated a sample - if a new feature was implemented (/example)

Device checks were not run. This is a TypeScript package-resolution fix verified through compiler reproductions, packaged regression checks, and example source type checking. A new feature sample is not applicable.

Screenshot OR Video

Not applicable: the failure occurs during TypeScript compilation.

Component to reproduce the issue you're fixing

Standalone TypeScript consumer reproducer

In a consumer project with @rnmapbox/maps and TypeScript installed, create these files without a paths alias.

index.ts:

import type { Expression } from '@rnmapbox/maps/src/utils/MapboxStyles';
import type { Props } from '@rnmapbox/maps/src/components/SymbolLayer';
import type { RegionPayload } from '@rnmapbox/maps/src/components/MapView';
import type { OnPressEvent } from '@rnmapbox/maps/src/types/OnPressEvent';

export const expression: Expression = ['get', 'myProp'];
export type ReportedTypes = Props | RegionPayload | OnPressEvent;

public.ts:

import type {
  Expression,
  FilterExpression,
  SymbolLayerProps,
  RegionPayload,
  GestureSettings,
  OnPressEvent,
} from '@rnmapbox/maps';

export const expression: Expression = ['get', 'myProp'];
export type PublicTypes =
  | FilterExpression
  | SymbolLayerProps
  | RegionPayload
  | GestureSettings
  | OnPressEvent;

tsconfig.json:

{
  "compilerOptions": {
    "strict": true,
    "skipLibCheck": true,
    "noEmit": true,
    "module": "ESNext",
    "moduleResolution": "bundler",
    "target": "ESNext",
    "types": []
  },
  "include": ["*.ts"]
}

Run:

npx tsc -p tsconfig.json

The unfixed base produces four TS2307 errors, five TS2614 errors, and one TS2724 error. The fixed package resolves these imports.

The committed package regression can be run with:

yarn jest __tests__/typeExports.test.js --runInBand

It requires no map rendering or device.

- Restore the four reported source type imports through explicit declaration exports
- Expose expression, style, symbol layer, map payload, and press event types publicly
- Verify built and packed outputs with generated package metadata and dependency types
- Cover private internal paths and Node runtime export rejection
@mfazekas

Copy link
Copy Markdown
Contributor

Thanks for the thorough investigation and the packaged test. We'd like to take this in a narrower form though. As mentioned on #4139, the src/ paths aren't public API, so we don't want to add them to the exports map. We also don't want a single exported Expression, since filter and per-property expressions may get different, stricter types. ComponentProps<typeof CircleLayer>['filter'] / CircleLayerStyle['circleColor'] stays correct when that happens. Could you drop the package.json subpath exports, the export type * from './utils/MapboxStyles', and the packaging test, and keep only the root exports for callback/prop shapes users can't easily name: OnPressEvent, RegionPayload, SymbolLayerProps (and CameraBoundsWithPadding from #4120 if you like)? Please skip Point, as it's too easy to confuse with GeoJSON Point.

This branch was previously deployed

1 inactive deployment
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.

[Bug]: Missing type exports

2 participants