nghiepdev / next-mobx-wrapper

[DEPRECATED] Mobx wrapper for Next.js
MIT License
12 stars 2 forks source link

typescript? #5

Open FDiskas opened 5 years ago

FDiskas commented 5 years ago

Can you generate typings?

FDiskas commented 5 years ago

It could be like so:

declare module 'next-mobx-wrapper' {
  import { ComponentType } from 'app/node_modules/@types/react';
  export declare const withMobx: (getStores?: {}) => (NextComponentType) => NextComponentType<{ store: any }>;

  export declare class BaseStore {
    constructor(props?: {});

    update: (data?: {}) => void;
  }

  export declare const getOrCreateStore: (string, initialState: any) => any;
  export declare const isServer: boolean;
  export declare const getKeyNameStore: (fnName: any) => any;
  export declare const mapToJson: (map: any) => any;
  export declare const jsonToMap: (jsonStr: any) => any;

  import * as React from 'react';
  import { NextComponentType } from 'next';
  declare const _default: (getStores?: {}) => (App: NextComponentType<{}, {}, import("next").NextContext<Record<string, string | string[] | undefined>, {}>>) => {
    new (props: any): {
      readonly store: {};
      render(): JSX.Element;
      context: any;
      setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
      forceUpdate(callBack?: (() => void) | undefined): void;
      readonly props: Readonly<{}> & Readonly<{
        children?: React.ReactNode;
      }>;
      state: Readonly<{}>;
      refs: {
        [key: string]: React.ReactInstance;
      };
    };
    getInitialProps(appContext: import("next/app").NextAppContext<Record<string, string | string[] | undefined>, {}>): Promise<{
      initialMobxState: any;
    }>;
    contextType?: React.Context<any> | undefined;
  };
  export default _default;

}
nghiepdev commented 5 years ago

@FDiskas thanks.

Can you help me make a pull request?

FDiskas commented 5 years ago

I believe that thous typings is wrong. Suggesting to rewrite project to typescript and then generate typings on build

You can either use tsc --declaration fileName.ts, or you can specify declaration: true under compilerOptions in your tsconfig.json assuming you've already had a project converted to typescript

Also typings can be added directly in this project. Simple example https://github.com/nfq-eta/react-router4-with-layouts

nghiepdev commented 5 years ago

I think this is just a small library and unnecessary rewriting. But, typing is necessary.