Repository navigation
Conversation
`src/index.ts` and `src/index.web.ts` had `export default ImageEditor` as
their only export. `types.ts` ships in the package but nothing re-exports it,
so the two types the README names are unreachable:
import type { ImageCropData } from '@react-native-community/image-editor';
// TS2614: Module has no exported member 'ImageCropData'
Consumers who want to type a crop-data variable have to hand-copy the shape —
which is what the example app had to do (`example/src/types.ts`).
Both entry points now re-export the same names, so the import works whichever
platform bundles.
Runtime is untouched; this is `export type` only.
The three overloads had two holes. A pre-typed `ImageCropData` variable with `includeBase64: true` set at runtime matched overload 1, so `r.base64` was TS2339 although the value was there — the example app's exact pattern, which pushes users to `(r as any).base64`. `includeBase64: someBoolean` matched no overload at all (TS2769) although it is runtime-valid. One generic signature keyed on the literal `includeBase64` value fixes both: `true` -> `base64: string`; `false`/absent -> no `base64`; a `boolean` that isn't statically known -> `base64?: string`, which is the honest answer when the branch can't be picked at compile time. Both entry points now declare the shared `CropImageFunction` shape, and `__typetests__` asserts native and web both satisfy it. That assertion covers the declared signature only, not runtime behavior — reintroducing the old "web always computes base64" bug leaves it clean, because `index.web.ts` casts its return through `as CropResultFor<B>` unconditionally. The comment there says so; a runtime test is the real fix for behavioral parity.
retyui
force-pushed
the
fix/api-exports-and-conditional-result
branch
from
December 2, 2026 16:15
221fbaf to
a3b72ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #220 — targets
fix/web-uri-and-includebase64, notmaster. Rebase ontomasterafter #220 merges (the web signature in the second commit depends on #220'sincludeBase64fix; without itindex.web.tsstill ignores the flag). Two commits, one finding each.7771fd3 — the public types aren't exported
src/index.tsandsrc/index.web.tshadexport default ImageEditoras their only export.types.tsships in the package but nothing re-exports it, so the two types the README names by name are unreachable:Consumers who want to type a crop-data variable have to hand-copy the shape — which is what the example app ended up doing (
example/src/types.ts). Both entry points now re-export the same names, so the import works whichever platform bundles.export typeonly; runtime untouched.71d7892 — the overload set has two holes
ImageCropDatavariable matches overload 1 even whenincludeBase64: trueis set at runtime, sor.base64is TS2339 while the value is present. That's the example app's exact pattern, and it pushes people to(r as any).base64.includeBase64: someBooleanhits no overload → TS2769, though it's runtime-valid.One generic signature fixes both:
true→base64: string;false/absent → nobase64; abooleannot known at compile time →base64?: string, which is the honest answer when the branch can't be picked statically.CropResultForuses[B] extends [true](notB extends true) so a nakedbooleandoesn't distribute into a union of both arms.The parity assertion is weaker than I first believed — and this PR says so in the code
__typetests__asserts both entry points satisfy the sharedCropImageFunction. I intended that to also catch web's runtime drift, then negative-tested it and it does not: reintroducing the pre-#220 bug (web always computingbase64) leaves the file clean, becauseindex.web.tscasts its return throughas CropResultFor<B>unconditionally. So the assertion checks declared signatures only, not that each platform implementsincludeBase64. The comment atsrc/__typetests__/index.tsnow states this limit explicitly rather than claiming a guarantee it doesn't give. Real behavioral parity needs a runtime test — out of scope here (the test-infrastructure PR is the right home for it).I also negative-tested the parts that do bite: degenerating
CropResultForto a plain alias producesTS2322at__typetests__/index.ts:22, so the conditional-type assertions aren't vacuous.Verification
yarn tscandeslint src/clean. The H5 assertions are load-bearing by construction: the typetests import through@react-native-community/image-editor(resolved tosrc/indexbytsconfig.jsonpaths), i.e. the same entry point consumers use, so TS2614 returns if the exports are dropped.ImageCropDatarequiresoffset/size, soconst typedParams: ImageCropData = requiredParamsalso fails if the shape drifts.Behavior change: new type errors are the point — code that passed a non-
booleantoincludeBase64, or relied onr.base64being absent for a pre-typed variable, may now fail to compile. Hence the changeset's minor bump.Part of a batch: #219 (types/codegen), #220 (web), #221 (Android), #222 (iOS).