typescript - 类型 'IntrinsicAttributes & IntrinsicClassAttributes' 上不存在属性 'children'
react-native-elements 中的 ThemeProvider 不允许有子元素。
这是代码:
const Root = () => {
const {theme, isNewUser} = Settings.useContainer();
const darkMode = useMemo(() => theme === 'dark', [theme]);
return (
<ThemeProvider theme={darkMode ? darkTheme : lightTheme} useDark={darkMode}>
{isNewUser ? <OnboardingStack /> : <BottomTab />}
</ThemeProvider>
);
};
ThemeProvider 显示红色下划线,悬停时它显示
Type '{ children: Element; theme: RCTheme; useDark: boolean; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<ThemeProvider> & Pick<Readonly<ThemeProviderProps>, never> & InexactPartial<...> & InexactPartial<...>'.
Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<ThemeProvider> & Pick<Readonly<ThemeProviderProps>, never> & InexactPartial<...> & InexactPartial<...>'.ts(2322)
答案#1
type ExistingThemeProviderProps = ComponentProps<typeof ThemeProvider> & {children: ReactNode};
export const ThemeProviderExtended = (props: ExistingThemeProviderProps) => <ThemeProvider {...props}/>
这解决了我的问题,直到 react-native-elements 团队发布类型修复为止。
