diff --git a/src/NativeRNCImageEditor.ts b/src/NativeRNCImageEditor.ts index 33e6e17..d5fcc26 100644 --- a/src/NativeRNCImageEditor.ts +++ b/src/NativeRNCImageEditor.ts @@ -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, diff --git a/src/__typetests__/index.ts b/src/__typetests__/index.ts index 98fbc86..374e77f 100644 --- a/src/__typetests__/index.ts +++ b/src/__typetests__/index.ts @@ -33,3 +33,27 @@ ImageEditorNative.cropImage('', { // @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('', { + // @ts-expect-error - offset.x must be a number + offset: { x: 'oops', y: 0 }, + size: { width: 100, height: 100 }, +}); +ImageEditorNative.cropImage('', { + offset: { x: 0, y: 0 }, + // @ts-expect-error - size.width must be a number + size: { width: 'wide', height: 100 }, +}); +ImageEditorNative.cropImage('', { + ...requiredParams, + // @ts-expect-error - quality must be a number + quality: 'high', +}); +ImageEditorNative.cropImage('', requiredParams).then((e) => { + // @ts-expect-error - width is a number + const w: string = e.width; +});