-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typing error for typescript #307
Comments
Better definition export function Feature(props: { inactiveComponent?: Component; activeComponent: Component; name: keyof ApplicationFeature }): JSX.Element;
export function Feature(props: { children: (args: { features: FeatureNames }) => JSX.Element }): JSX.Element; Better yet (because it's augmentable) export interface Feature {
(props: { inactiveComponent?: Component; activeComponent: Component; name: string }): JSX.Element;
(props: { children: (args: { features: FeatureNames }) => JSX.Element }): JSX.Element;
}
export const Feature: Feature; Best (allows the user to use their own string literals) export interface Feature {
(props: { inactiveComponent?: Component; activeComponent: Component; name: keyof ApplicationFeature }): JSX.Element;
(props: { children: (args: { features: FeatureNames }) => JSX.Element }): JSX.Element;
}
export const Feature: Feature;
export interface ApplicationFeature {} In your app: import { FeatureFlag } from 'someplace/in/the/app';
declare module '@paralleldrive/react-feature-toggles' {
export interface ApplicationFeature extends Record<FeatureFlag, unknown> {}
} |
In later versions of react, SFC and StatelessComponent are deprecated. Meaning that typescript will not identify the correct Feature type you want if you have functional components. I therefore suggest that you replace this type Component = ComponentClass | SFC<any> | StatelessComponent;
export function Feature(props: {
children: (args: { features: FeatureNames }) => JSX.Element;
}): JSX.Element;
export function Feature(props: {
inactiveComponent?: Component;
activeComponent: Component;
name: string;
}): JSX.Element; to type Component = ComponentClass | FunciontComponent;
export function Feature(props: {
children: (args: { features: FeatureNames }) => JSX.Element;
}): JSX.Element;
export function Feature(props: {
inactiveComponent?: Component;
activeComponent: Component;
name: string;
}): JSX.Element; in your index.d.ts file. I can create a PR in order to speed things a long 😃 . |
I was trying to include Feature for my tsx file; however, my code editor shows me a typing error.
code:
Error:
The text was updated successfully, but these errors were encountered: