Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Can someone explain to me what does 'as never' do in this piece of code?

$
0
0

Like the title says, I'm confused as to what 'as never' means in this piece of code. I read that it's supposed to mean something that never occurs or excludes other types but I'm not quite grasping why it's being used the way it is in the piece of code below.

import { View, Button, Text, StyleSheet, FlatList, TouchableOpacity, Image } from 'react-native'import React from 'react'import { useNavigation } from '@react-navigation/native'const data = [  {    id: 1,    title: 'Google Search',    screen: 'MapScreen',  },  {    id: 2,    title: 'I\'m Feeling Lucky',    screen: 'MapScreen',  }]const NavOptions = (props: NavProps) => {  const navigation = useNavigation();  return (<FlatList      data={data}      keyExtractor={(item) => item.id}      horizontal      renderItem={({ item }) => (<View style={styles.container}><TouchableOpacity            onPress={() => props.term && navigation.navigate(item.screen as never, {              term: props.term,            } as never)}            style={styles.button}><Text style={styles.text}>{item.title}</Text></TouchableOpacity></View>      )}    />  )}const styles = StyleSheet.create({  container: {    padding: 10,  },  button: {    backgroundColor: "#f8f9fa",    padding: 10,  },  text: {    color: "black",    textAlign: "center",  },});type NavProps = {  term: string;}export default NavOptions

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>