NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

Type 'Element' is not assignable to type 'TabHeading'

Open mengyiyuan opened this issue 9 years ago • 12 comments

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'. Types of property 'heading' are incompatible. Type 'Element' is not assignable to type 'TabHeading'."

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

mengyiyuan avatar Oct 13 '17 09:10 mengyiyuan

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 avatar Oct 15 '17 02:10 mengyiyuan

@mengyiyuan couldn't reproduce the error. Attaching a screen shot tabheading 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/>

akhil-ga avatar Oct 16 '17 07:10 akhil-ga

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

mengyiyuan avatar Oct 16 '17 10:10 mengyiyuan

Yes, i tested this in Typescript

akhil-ga avatar Oct 16 '17 10:10 akhil-ga

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 avatar Oct 16 '17 11:10 mengyiyuan

@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"
	}
}

akhil-ga avatar Oct 24 '17 09:10 akhil-ga

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'.

wallel avatar Nov 03 '17 06:11 wallel

Does this plan on being fixed soon, or is there a workaround available?

DustinEwan avatar Dec 07 '17 03:12 DustinEwan

I'm trying to use Native Base and Typescript together for a client but hitting a wall. Any suggestion on this is greatly appreciated.

DustinEwan avatar Dec 08 '17 20:12 DustinEwan

Bumping for an update. I'm really wanting to use NativeBase, but my priority on the project is Typescript.

Thanks!

DustinEwan avatar Dec 11 '17 16:12 DustinEwan

I meet the same issue.

qinyang1980 avatar Dec 22 '17 09:12 qinyang1980

Fixed with 2.3.6

SupriyaKalghatgi avatar Jan 05 '18 06:01 SupriyaKalghatgi