Repository navigation
fix(types): accept an explicit undefined wherever a consumer writes an optional member - #418
Draft
YevheniiKotyrlo wants to merge 3 commits into
Draft
YevheniiKotyrlo wants to merge 3 commits into
YevheniiKotyrlo wants to merge 3 commits into
Conversation
Contributor
Author
YevheniiKotyrlo
force-pushed
the
rncss/types-optional-undefined
branch
from
October 11, 2026 12:35
6c6da94 to
d10ad90
Compare
YevheniiKotyrlo
marked this pull request as draft
October 20, 2026 09:53
…s package declares
React Native declares its optional props as `?: T | undefined`, and the props
this package adds were bare `?: string`. Under exactOptionalPropertyTypes the
two differ, so `className={condition ? "p-4" : undefined}` failed to compile,
and declaration merging cannot widen an existing prop from the consumer side.
Every optional member of types.d.ts and runtime.types.ts now takes
`| undefined`, except InlineStyleRecord's `s?: never`, which marks a key that
must stay absent. The props a mapping adds come from one StyledSourceProps
type, which the unmapped overload uses with DefaultStyledConfiguration, the
default mapping both platforms pass.
A test walks both files with the type checker under the flag and fails on any
optional member that rejects undefined, so a member added later is covered too.
…an entry left undefined
StyledConfigurationObject called ResolveDotPath<T, ComponentProps<C>>, the
reverse of its declaration ResolveDotPath<T, Path>, so a string target's
mapping type was never and only the target:false branch's Record checked a
mapping. With the arguments in order, an entry may be left undefined, and
mappingToConfig drops it, where nativeStyleMapping called `path.split(".")` on
it and threw.
YevheniiKotyrlo
force-pushed
the
rncss/types-optional-undefined
branch
from
October 20, 2026 15:02
8c8919f to
49ff1c9
Compare
…in a mapping A nativeStyleMapping key names a key of the compiled style, which a -rn- declaration can add under any name, so its keys stay open while React Native's style keys complete; the type no longer resolves the target, which halves its instantiations. The class props styled() adds stay writable, and the compiler, Metro, jest, Babel and useNativeCss options accept an explicit undefined.
This branch has not been deployed
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.


Problem
React Native declares its own optional props as
?: T | undefined, while the props this package adds are bare?: string. UnderexactOptionalPropertyTypesthe two differ, and the difference falls on the most ordinary thing a consumer writes:styled()has the same bare members: theclassNameits unmapped overload adds,passThrough, and a mapping'snativeStyleMapping; so do the options a consumer writes for the compiler, Metro, the jest helper, the Babel plugin anduseNativeCss. A consumer's own declaration that widens such a prop takes effect only when it comes before this package's in the program.A mapping entry left
undefinedis also a runtime error:mappingToConfigkeeps it, andnativeStyleMappingcallspath.split(".")on it:Solution
types.d.tsandruntime.types.ts, and of the compiler's, Metro's, the jest helper's, the Babel plugin's anduseNativeCss's options, takes| undefined, as React Native writes its own, exceptInlineStyleRecord'ss?: never, which marks a key that must stay absent.styled()mapping adds come from oneStyledSourcePropstype, whichStyledProps,StyledReactElementandStyledComponentuse, and which the unmapped overload uses withDefaultStyledConfiguration, the default mappingsrc/native/api.tsxandsrc/web/api.tsxboth pass. They stay writable, as the component's own props are.-rn-declaration, so any string is a key. The type no longer resolves the mapping's target, and an entry may be leftundefined, whichmappingToConfigdrops.Tests
src/__tests__/types/optional-members.test.tswalks both declaration files and the option types with the type checker, the flag on, and fails on any optional member that rejectsundefined: a property, a class property, a method, a tuple element, a mapped type overkeyof Tor aK extends keyof T, even behind an alias, and a library type such asPartialthat adds?, in an alias, anextendsclause or over a type parameter. Its fixture holds each form, beside an alias,void, an indexed access and a mapped type that keeps each member's own type, which pass. Againstmainit reports 40 members; here none.src/__tests__/types/styled.test.tscompiles mappings through the type checker: any style key, a-rn-declaration's among them, is accepted, a value naming no prop is rejected, the editor completes React Native's style keys whatever the target, and the class props stay writable. Three of its cases fail onmain.src/__tests__/native/styled.test.ios.tsx: a mapping entry set toundefinedmaps nothing. Onmainthe case failstsc, and its render throws.Verification
Every
ci.ymljob passes on this head merged intomainwith #477's harness fix: lint, typecheck, the tests (1350 passed), both builds, the web export, nothing unstaged, commitlint, and the iOS dev build on macOS 27.0.1 with Xcode 27.0, where CI pins 26.6.A
styled()mapping now costs the type checker about 8,100 instantiations against 35,200 onmain, andtsc --noEmitover this repository makes 929,290 type instantiations against 979,442. The runs, and the snippet above onmainand on this branch, are in this comment.Known limits
-rn-declaration can add any key to the style.styled()over Reanimated's animated components still exceeds the type checker's depth (TS2589, TS2590), as onmain, at about 15% fewer instantiations.main.Merge order
dir?: "ltr" | "rtl"toViewPropsandTextProps. Whichever lands second widens it, and this test fails until it does.