react-native-themed-styles icon indicating copy to clipboard operation
react-native-themed-styles copied to clipboard

Type error when putting functionality into a separate module

Open djMax opened this issue 4 years ago • 0 comments

I have a monorepo with a module dedicated to themes with a very simple signature:

import { registerThemes } from 'react-native-themed-styles';
import { useColorScheme } from 'react-native-appearance';
import * as themes from './themes';

export const styleSheetFactory = registerThemes(themes, () => {
  const colorScheme = useColorScheme();
  if (colorScheme === 'dark') {
    return 'dark';
  }
  return 'light';
});

export { useTheme } from 'react-native-themed-styles';

When I have "declarations: true" in my tsconfig, which is generally good I assume, so that callers can get good typing, I get this error:

src/index.ts:5:14 - error TS4023: Exported variable 'styleSheetFactory' has or is using name 'StyleSheetData' from external module "/Users/memetral/dev/gb/app/node_modules/react-native-themed-styles/index" but cannot be named.

5 export const styleSheetFactory = registerThemes(themes, () => {
               ~~~~~~~~~~~~~~~~~

I'm a bit of a newcomer to Typescript, so I couldn't quite untangle why this was happening, but seems like it's because StyleSheetData and related types are not exported.

djMax avatar Jun 12 '20 00:06 djMax