以下代码会引发错误。该代码是重现原始错误的最小可执行代码。
import React from 'react';
import { Button, StyleSheet } from 'react-native';
const MyButton = () => {
return (
<Button
title="Click me"
style={styles.button}
/>
);
};
const styles = StyleSheet.create({
button: {
backgroundColor: '#0f0',
color: '#fff',
padding: 10,
},
});
错误:
No overload matches this call.
Overload 1 of 2, '(props: ButtonProps): Button', gave the following error.
Type '{ title: string; style: { backgroundColor: string; color: string; padding: number; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Button> & Readonly<ButtonProps>'.
Property 'style' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Button> & Readonly<ButtonProps>'.
Overload 2 of 2, '(props: ButtonProps, context: any): Button', gave the following error.
Type '{ title: string; style: { backgroundColor: string; color: string; padding: number; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Button> & Readonly<ButtonProps>'.
Property 'style' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Button> & Readonly<ButtonProps>'.ts(2769)
结果,React Native 网页是空的。
我检查了以下几页,但没有成功。
属性“样式”不存在...