vitalets / react-native-extended-stylesheet

Extended StyleSheets for React Native
MIT License
2.93k stars 132 forks source link

fix: type declaration error #160

Closed onlyling closed 2 years ago

onlyling commented 3 years ago
import EStyleSheet from 'react-native-extended-stylesheet'

EStyleSheet.value('$someVar')

When used with eslint-plugin-import, it prompts many questions, such as import/namespace, import/no-named-as-default, import/no-named-as-default-member.

If I use the following method, Babel will prompt an error.

import * as EStyleSheet from 'react-native-extended-stylesheet'

EStyleSheet.value('$someVar')

The export default export is used in src/index.js, I think the declaration should be changed.

The error message disappeared after I modified the local file.

At the same time, it can also be solved by overwriting the declaration.

export function value<T>(expr: any, prop?: string): T T is right?

import type { StyleSheet } from 'react-native'

declare namespace EStyleSheet {
  type AnyObject<T = {}> = T & { [key: string]: any }
  type Event = 'build'

  export function create<T>(styles: AnyObject<T>): AnyObject<T>
  export function build<T>(rawGlobalVars?: T): void
  export function value<T>(expr: any, prop?: string): T
  export function child<T>(
    styles: T,
    styleName: string,
    index: number,
    count: number,
  ): T
  export function subscribe(event: Event, listener: () => any): void
  export function clearCache(): void

  // inherited from StyleSheet
  export const flatten: typeof StyleSheet.flatten
  export const setStyleAttributePreprocessor: typeof StyleSheet.setStyleAttributePreprocessor
  export const hairlineWidth: typeof StyleSheet.hairlineWidth
  export const absoluteFillObject: typeof StyleSheet.absoluteFillObject
  export const absoluteFill: typeof StyleSheet.absoluteFill
}

declare module 'react-native-extended-stylesheet' {
  export default EStyleSheet
}
stale[bot] commented 2 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.