Repository navigation
fix(types): accept an explicit undefined on every added prop, styled() option and mapping entry - #418
Draft
YevheniiKotyrlo wants to merge 2 commits into
Draft
YevheniiKotyrlo wants to merge 2 commits into
YevheniiKotyrlo wants to merge 2 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
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.A consumer cannot fix it locally, because declaration merging can add props but not widen an existing one.
A mapping's entries have a gap of their own.
StyledConfigurationObjectresolves a string target withResolveDotPath<T, ComponentProps<C>>, the reverse of its declaration, so a target's own mapping type isneverand only thetarget: falsebranch'sRecordchecks a mapping. At runtimemappingToConfigkeeps an entry leftundefined, andnativeStyleMappingcallspath.split(".")on it:Solution
types.d.tsandruntime.types.tstakes| 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.ResolveDotPathtakes its arguments in declared order, so a mapping is also typed by its target's keys, each of which may be leftundefined, andmappingToConfigdrops such an entry.Tests
src/__tests__/types/optional-members.test.tswalks both files 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 over aK extends keyof T, and a library type such asPartialthat adds?. Its fixture holds each of those forms, beside an alias,voidand an indexed access that includeundefined, which pass. Againstmainit reports 21 members, 12 intypes.d.tsand 9 inruntime.types.ts; here it reports none.src/__tests__/native/styled.test.ios.tsx: a mapping entry set toundefinedmaps nothing. Onmainthe case failstsc, and its render throws.With the flag on,
<StyledView className={maybeString} />forstyled(View),passThrough: maybeFlag,nativeStyleMapping: maybeMappingand a mapping entry leftundefinedeach fail onmainand compile here.Verification
Every
ci.ymljob passes on this head merged intomainwith #477's harness fix: lint, typecheck, the tests (1344 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.With the mapping's own branch live,
tsc --noEmitover this repository instantiates 8.0% more types (1,058,545 against 979,787), and its check time moves from 2.85 s to 3.07 s, medians of five runs. The runs, and the snippet above onmainand on this branch, are in this comment.Known limits
types.d.tsandruntime.types.tsonly. The compiler's and Metro's options, the jest helper'sdebugand the Babel plugin'starget,runtimeandcommonjskeep bare optional members, and the package's own code has 17 errors under the flag, in eight files, as onmain.Merge order
dir?: "ltr" | "rtl"toViewPropsandTextProps. Whichever lands second widens it, and this test fails until it does.