I have an error when compile ts file, and I still do not know how to solve it after searching some references, any ideas?
my code is as follows:
import * as React from 'react'
import { View, Text, Image, TouchableOpacity, StyleSheet } from 'react-native'
import * as CONST from '../../CONST'
/**定义组件props */
export interface props{
isVisible: boolean
closeDialog?: () => void
}
export interface States {
}
export class Dialog extends React.Component<props,States>{
constructor(props: props) {
super(props);
}
static defaultProps = {
isVisible: false
};
render() {
return (
this.props.isVisible ?
<TouchableOpacity style={[styles.container, { width: CONST.WIDTH, height: CONST.HEIGHT }]} onPress={this.props.closeDialog.bind(this)}>
</TouchableOpacity>
: null
)
}
}
const styles = StyleSheet.create({
container: {
position: 'absolute',
zIndex: 1000,
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'rgba(0,0,0,0.2)'
}
})
but when I compile it, the console page gets an error like this :
js/components/dialog/dialog.component.tsx(19,18): error TS2339: Property 'props' does not exist on type 'Dialog'
the completed demo code address is here
I'd help you but line 19 doesnt match up correctly and there is no Typings defined above.
There are a few issues going on here. First you have @types/node and typings\global\node, these two pretty much define the same thing. I have a PR changing this in https://github.com/SunShinewyf/myApp/pull/1.
There is another issue on the declaration file for react-native, I have a fix up in https://github.com/DefinitelyTyped/DefinitelyTyped/pull/13952.
@ericanderson sorry, I put wrong code on this platform and update it now
@mhegazy Thanks in advance , I try it as your way and it compile with no error , but I am confused that why using typings has this error , Can you provided more details about your reason to use this case
i did not see the error you mentioned when i ran your repo. the only thing i saw was conflicts between typings\global\node\index.d.ts and node_modules\@types\node\index.d.ts, which you have both in your project.
@mhegazy
I know, thank you very much , but I still want to know why you help me to add these lines
"@types/autobind-decorator": "^1.3.2",
"@types/htmlparser2": "^3.7.29",
"@types/lodash": "^4.14.48",
"@types/react": "^15.0.0",
"@types/react-native": "^0.37.6",
"@types/react-redux": "^4.4.35",
"@types/redux": "^3.6.0",
"@types/redux-persist": "^4.0.0",
"@types/redux-thunk": "^2.1.0",
"@types/whatwg-fetch": "0.0.33",
the previous package.json file did not have these lines and it can not have conflicts between typings folders
before you had @types/node: https://github.com/SunShinewyf/myApp/blob/7c2e8d6506028fe7cd81cbebc0b0312404c0f760/package.json#L22