Repository navigation
Keep null in the TypeScript type of Image.resolveAssetSource - #59713
Hassan1305 wants to merge 1 commit into
Conversation
resolveAssetSource returns null for an asset the registry does not hold, but the generated TypeScript declared `ImageResolvedAssetSource | undefined`: `?T` on an object type member is translated to `T | undefined`. Move the return type to a module-level alias, which translates to `ImageResolvedAssetSource | null | undefined`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @Hassan1305! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary:
Fixes #59648.
Image.resolveAssetSourcereturnsnullfor an asset id the registry does not hold, and its Flow type (?ImageResolvedAssetSource) allows that. The generated TypeScript declaresImageResolvedAssetSource | undefined, becausereplaceNullablePropertiesWithUndefinedtranslates?Ton an object type member toT | undefined. TypeScript code that only rules outundefinedtherefore compiles and then throws onnull.This moves the return type to a module-level alias, which the transform does not touch, so it generates
ImageResolvedAssetSource | null | undefined. The Flow type is unchanged in meaning.TypeScript users who only check
!== undefinedwill now get a compile error at that line. That is the intended effect, but it can surface in existing code.The transform affects other object type members too. I kept this change to the one reported method rather than changing the transform, since that would alter much of the public API. The hand-written
types_DEPRECATED/Libraries/Image/Image.d.tsalso omitsnulland is unchanged here.Changelog:
[GENERAL] [FIXED] - Include
nullin the TypeScript return type ofImage.resolveAssetSourceTest Plan:
No test is added:
__typetests__compiles withstrict: false, where a missingnullcan't be detected. Instead I compiled this file with a temporary tsconfig extending__typetests__/tsconfig.jsonwithstrict: true, usingtsc -p:issueLineerrors, witherror TS18047: 'r' is possibly 'null'.Commands run locally on Node 24, all passing:
node ./scripts/run-ci-javascript-tests.js --maxWorkers 4(feature flags, lint, API snapshot, Flow, Jest: 262 suites, 6458 passed, 1 skipped)yarn lint-markdown,yarn lint,yarn flow-checkyarn test-typescript-legacyyarn build-types --skip-snapshotandyarn test-generated-typescriptyarn build-types --validateyarn format-check-javascriptNot run locally: Node 22,
analyze_scripts.sh(shellchecknot installed; no shell scripts changed), and the Android, iOS and Fantom jobs (no native code changed).🤖 Generated with Claude Code