Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/NativeRNCImageEditor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import type { TurboModule } from 'react-native';
import type {
Double,
Float,
Int32,
// @ts-expect-error TS2307 Cannot find module '../CodegenTypes'
} from 'react-native/Libraries/Types/CodegenTypes';
import { TurboModuleRegistry } from 'react-native';

/**
* Codegen scalar aliases, declared locally instead of imported from
* `react-native/Libraries/Types/CodegenTypes`.
*
* That deep import has no resolvable types under React Native's own
* `exports` map (`./Libraries/*` sets `"types": null`), so importing it
* silently degrades every `Double`/`Float`/`Int32` below to `any` for this
* library *and* for every consumer of the published `.d.ts` — the whole
* numeric surface of the public API stops type-checking. Codegen matches
* these scalars by identifier name and does no module resolution, so local
* aliases produce a byte-identical schema.
*/
type Double = number;
type Float = number;
type Int32 = number;

export interface Spec extends TurboModule {
cropImage(
uri: string,
Expand Down
24 changes: 24 additions & 0 deletions src/__typetests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,27 @@ ImageEditorNative.cropImage('<test>', {
// @ts-expect-error - base64 doesn't exist
const a: string = e.base64;
});

// Regression guard for the `CodegenTypes` deep import collapsing every
// `Double`/`Float`/`Int32` in the public API to `any`. If that import ever
// comes back, the directives below become "Unused '@ts-expect-error'" and
// `yarn ts` fails. See `src/NativeRNCImageEditor.ts`.
ImageEditorNative.cropImage('<test>', {
// @ts-expect-error - offset.x must be a number
offset: { x: 'oops', y: 0 },
size: { width: 100, height: 100 },
});
ImageEditorNative.cropImage('<test>', {
offset: { x: 0, y: 0 },
// @ts-expect-error - size.width must be a number
size: { width: 'wide', height: 100 },
});
ImageEditorNative.cropImage('<test>', {
...requiredParams,
// @ts-expect-error - quality must be a number
quality: 'high',
});
ImageEditorNative.cropImage('<test>', requiredParams).then((e) => {
// @ts-expect-error - width is a number
const w: string = e.width;
});
Loading