Type 'Element' is not assignable to type 'TabHeading'
react-native, react and native-base version
react-native: 0.49.1 react: 16.0.0 native-base: 2.3.2 typescript: 2.5.3
Expected behaviour
Tab component should accept a heading props of type TabHeading
Actual behaviour
Typescript complains that:
"Type '{ heading: Element; children: Element; }' is not assignable to type 'Readonly
Steps to reproduce (code snippet or screenshot)
class TypeTabs extends React.Component {
public render() {
return (
<Header hasTabs={true}>
<Tabs>
<Tab heading={"Search By Name"}>
<SearchPage />
</Tab>
<Tab heading={ <TabHeading><Text>Fuzzy Search</Text></TabHeading>}>
<SearchPage />
</Tab>
</Tabs>
</Header>
);
}
}
Screenshot of emulator/device
Cannot compile by running npm run start:ios due to the error above.
Is the bug present in both ios and android or in any one of them?
Same, because it's compilation error.
Any other additional info which would help us debug the issue quicker.
As shown above, I have followed the example both in simple tabs and advanced tabs format, but none works. The documentation I was referring to is here: https://docs.nativebase.io/Components.html#tabs-def-headref
After digging into the index.d.ts file, it seems that the heading prop of the Tab element is wrongly bind to the TabHeading class, instead of a React Native component type. Is there any reason behind this? How do you get it to properly work with TypeScript's type checking.
@mengyiyuan couldn't reproduce the error. Attaching a screen shot
Code
<Header hasTabs={true}>
<Tabs>
<Tab heading={"Search By Name"}>
<View/>
</Tab>
<Tab heading={ <TabHeading><Text>Fuzzy Search</Text></TabHeading>}>
<View/>
</Tab>
</Tabs>
</Header>
TabHeading is binded with Tab because we recommend using <TabHeading/> with header prop of <Tab/>
Hello Thanks for your reply. May I know if you are using TypeScript, since the error is thrown by ts compiler because the type of the heading prop is cannot be complied with the code above. Thanks, Mengyi
Yes, i tested this in Typescript
Is it possible to quickly share with me your project setup to realize your testing above? I tried so many things and nothing seemed to solve this issue for me somehow.
@mengyiyuan
{
"name": "ReactNativeSeed",
"version": "1.0.0",
"private": true,
"devDependencies": {
"@types/jest": "^20.0.8",
"@types/react": "^16.0.5",
"@types/react-native": "^0.47.7",
"@types/react-native-vector-icons": "^4.3.1",
"@types/react-navigation": "^1.0.19",
"babel-eslint": "7.2.3",
"babel-jest": "20.0.3",
"babel-preset-react-native": "3.0.1",
"concurrently": "^3.5.0",
"eslint": "4.6.1",
"husky": "0.14.3",
"jest": "20.0.4",
"jest-expo": "20.0.0",
"react-native-scripts": "1.3.1",
"react-test-renderer": "16.0.0-alpha.12",
"rimraf": "^2.6.1",
"ts-jest": "^21.0.1",
"tslint": "^5.6.0",
"typescript": "^2.4.2"
},
"main": "node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "npm run build && concurrently -r 'npm run watch' 'react-native-scripts start'",
"eject": "react-native-scripts eject",
"test": "jest && tslint src/**/*.ts && eslint .",
"watch": "npm run build -- -w",
"ios": "npm run build && concurrently -r 'npm run watch' 'react-native-scripts ios'",
"android": "npm run build && concurrently -r 'npm run watch' 'react-native-scripts android'",
"tsc": "tsc",
"clean": "rimraf artifacts",
"build": "npm run clean && npm run tsc --",
"lint": "tslint src/**/*.ts",
"precommit": "yarn test"
},
"jest": {
"preset": "jest-expo",
"moduleFileExtensions": ["ts", "tsx", "js"],
"transform": {
"^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"transformIgnorePatterns": [
"node_modules/(?!(react-native|lottie-react-native|expo|react-native-maps|react-native-svg|react-native-branch|native-base-shoutem-theme|react-native-easy-grid|react-native-drawer|react-native-vector-icons|react-native-keyboard-aware-scroll-view|react-navigation|native-base|@expo|react-native-scrollable-tab-view)/)"
]
},
"dependencies": {
"expo": "21.0.2",
"lodash": "4.13.1",
"moment": "2.13.0",
"native-base": "2.3.2",
"react": "16.0.0-alpha.12",
"react-native": "0.48.4",
"react-navigation": "1.0.0-beta.11",
"react-redux": "5.0.5",
"redux": "3.7.2",
"redux-form": "7.0.3",
"redux-persist": "4.8.3",
"redux-thunk": "2.2.0",
"remote-redux-devtools": "0.5.0",
"remote-redux-devtools-on-debugger": "^0.8.0"
}
}
same problem, my typescript version:2.6.1
Type '{ heading: Element; children: never[]; }' is not assignable to type 'Readonly<Tab>'.
Types of property 'heading' are incompatible.
Type 'Element' is not assignable to type 'TabHeading'.
Property 'setState' is missing in type 'Element'.
Does this plan on being fixed soon, or is there a workaround available?
I'm trying to use Native Base and Typescript together for a client but hitting a wall. Any suggestion on this is greatly appreciated.
Bumping for an update. I'm really wanting to use NativeBase, but my priority on the project is Typescript.
Thanks!
I meet the same issue.
Fixed with 2.3.6