& {
- [K in keyof M as K extends string
- ? M[K] extends undefined | false
- ? never
- : M[K] extends true | string | object
- ? K
- : never
- : never]?: string;
- }
->;
-
-export type StyledProps> = P & {
- [K in keyof M as K extends string
+type StyledSourceProps = {
+ -readonly [K in keyof M as K extends string
? M[K] extends undefined | false
? never
: M[K] extends true | string | object
? K
: never
- : never]?: string;
+ : never]?: string | undefined;
};
+export type StyledReactElement<
+ C extends ReactComponent,
+ M extends StyledConfiguration,
+> = ReactElement & StyledSourceProps>;
+
+export type StyledProps> = P &
+ StyledSourceProps;
+
export interface Styled {
(
component: C,
mapping?: undefined,
options?: StyledOptions,
- ): ComponentType & { className?: string }>;
+ ): ComponentType<
+ ComponentPropsWithRef & StyledSourceProps
+ >;
>(
component: C,
mapping: M & StyledConfiguration,
@@ -61,17 +56,11 @@ export interface Styled {
type StyledComponent<
C extends ReactComponent,
M extends StyledConfiguration,
-> = ComponentType<
- ComponentPropsWithRef & {
- [K in keyof M as K extends string
- ? M[K] extends undefined | false
- ? never
- : M[K] extends true | string | object
- ? K
- : never
- : never]?: string;
- }
->;
+> = ComponentType & StyledSourceProps>;
+
+export interface DefaultStyledConfiguration {
+ readonly className: "style";
+}
export type StyledConfiguration<
C extends ReactComponent,
@@ -88,27 +77,21 @@ interface StyledConfigurationObject<
T extends ComponentPropsDotNotation | false,
> {
target: T;
- nativeStyleMapping?: T extends false
- ? NativeStyleMapping>
- : NativeStyleMapping<
- ResolveDotPath>,
- ComponentProps
- >;
+ nativeStyleMapping?: NativeStyleMapping> | undefined;
/** @deprecated Please use nativeStyleMapping */
nativeStyleToProp?: StyledConfigurationObject["nativeStyleMapping"];
}
-type NativeStyleMapping = T extends object
- ? {
- [K in keyof T as K extends string ? K : never]: true | DotNotation;
- } & {
- fill?: true | DotNotation;
- stroke?: true | DotNotation;
- }
- : Record>;
+// A -rn- declaration puts its camel-cased name in the style, so a key may be any string beside React Native's style keys
+type NativeStyleMapping = Readonly<
+ Partial>>
+> &
+ Readonly>>;
+
+type NativeStyleMappingValue = true | DotNotation | undefined;
export interface StyledOptions {
- passThrough?: boolean;
+ passThrough?: boolean | undefined;
}
/*************************** React Helpers ***************************/
diff --git a/src/web/api.tsx b/src/web/api.tsx
index 28e09ab8..7e0aea9e 100644
--- a/src/web/api.tsx
+++ b/src/web/api.tsx
@@ -1,9 +1,4 @@
-import {
- createElement,
- useMemo,
- type ComponentType,
- type PropsWithChildren,
-} from "react";
+import { createElement, useMemo, type PropsWithChildren } from "react";
import { Appearance } from "react-native";
import type {
@@ -13,12 +8,16 @@ import type {
StyledOptions,
} from "react-native-css";
-import type { ReactComponent, Styled } from "../runtime.types";
+import type {
+ DefaultStyledConfiguration,
+ ReactComponent,
+ Styled,
+} from "../runtime.types";
import { assignStyle } from "./assign-style";
-const defaultMapping: StyledConfiguration> = {
+const defaultMapping = {
className: "style",
-};
+} as const satisfies DefaultStyledConfiguration;
export const styled: Styled = (
baseComponent: ReactComponent,
diff --git a/types.d.ts b/types.d.ts
index 924b9a7d..9811ec12 100644
--- a/types.d.ts
+++ b/types.d.ts
@@ -10,44 +10,44 @@ import type {
declare module "@react-native/virtualized-lists" {
export interface VirtualizedListWithoutRenderItemProps
extends ScrollViewProps {
- ListFooterComponentClassName?: string;
- ListHeaderComponentClassName?: string;
+ ListFooterComponentClassName?: string | undefined;
+ ListHeaderComponentClassName?: string | undefined;
}
}
declare module "react-native" {
interface ButtonProps {
- className?: string;
+ className?: string | undefined;
}
interface ScrollViewProps
extends ViewProps,
ScrollViewPropsIOS,
ScrollViewPropsAndroid,
Touchable {
- contentContainerClassName?: string;
+ contentContainerClassName?: string | undefined;
}
interface FlatListProps extends VirtualizedListProps {
- columnWrapperClassName?: string;
+ columnWrapperClassName?: string | undefined;
}
interface ImageBackgroundProps extends ImagePropsBase {
- imageClassName?: string;
+ imageClassName?: string | undefined;
}
interface ImagePropsBase {
- className?: string;
+ className?: string | undefined;
}
interface ViewProps {
- className?: string;
+ className?: string | undefined;
}
interface TextProps {
- className?: string;
+ className?: string | undefined;
}
interface SwitchProps {
- className?: string;
+ className?: string | undefined;
}
interface TouchableWithoutFeedbackProps {
- className?: string;
+ className?: string | undefined;
}
interface KeyboardAvoidingViewProps extends ViewProps {
- contentContainerClassName?: string;
+ contentContainerClassName?: string | undefined;
}
}