fast-styles icon indicating copy to clipboard operation
fast-styles copied to clipboard

[Expo] Typescript error using useMode

Open atanaskanchev opened this issue 2 years ago • 1 comments

Describe the bug Typescript error using useMode();

To Reproduce Implementing the modes guide

Reproducible example

import { ModeProvider, useMode } from "@fast-styles/react";
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
import StyledView from "./StyledView";

export default function App() {
  const [mode] = useMode();

  return (
    <ModeProvider>
      <View style={styles.container}>
        <Text>Open up App.tsx to start working on your app!</Text>
        <StyledView mode={mode}>
          <Text>Styled View</Text>
        </StyledView>
        <StatusBar style="auto" />
      </View>
    </ModeProvider>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});
image

Expected behavior Typescript errors should not happen

Environment "@fast-styles/babel-plugin": "^0.2.3", "@fast-styles/react": "^0.2.9", "expo": "~49.0.8", "expo-status-bar": "~1.6.0", "react": "18.2.0", "react-native": "0.72.4"

atanaskanchev avatar Sep 01 '23 10:09 atanaskanchev

Currently, TypeScript infers the return of useMode by combining the types. I'm going to modify it to work with individual types based on position.

Using as const on the result might do the trick. Thank you.

fedemartinm avatar Sep 01 '23 11:09 fedemartinm