typed-typings/npm-ramda

[Help] `Compose` [ts] Expected 0 arguments, but got 1.

tomzaku opened this issue · 1 comments

My code look like this

import { compose, map, path, filter, isNil, values, mergeAll, pick } from 'ramda'
// tslint:disable-next-line:no-duplicate-imports

import { module } from '../module/module'

interface IOptionType {
  type?: 'array' | 'flatten' | 'list'
}
interface IReduxType {
  reducer?: Function,
  saga?: Function,
  thunk?: Function
}
interface IPageType {
  [key: string]: any,
}
interface IPageListType {
  [key: string]: IPageType
}
interface IModuleType {
  redux?: IReduxType,
  page?: IPageListType
}

type ReduxKey = 'reducer' | 'action' | 'saga'

export const pathDict = (data: typeof module, rootPath: string[], options: IOptionType = {}) => {
  const { type } = options
  const getListData = map((eachModule: IModuleType) => path(rootPath)(eachModule))
  const removeUndefinedItem = filter((item: any) => !isNil(item))
  const listCompose = compose(removeUndefinedItem, getListData)
  switch (type) {
    case 'array': return compose(values, listCompose)(data) // <<<<<<<<  [ts] Expected 0 arguments, but got 1.
    case 'flatten': return compose(mergeAll, values, listCompose)(data) // <<<<<<<  [ts] Expected 0 arguments, but got 1.
    case 'list':
    default: return listCompose(data)
  }
}


export const getSpecificModuleRedux = (key: ReduxKey, options?: IOptionType) => pathDict(module, ['redux', key], options)
export const getPageList = () => pathDict(module, ['page', 'route'], { type: 'array' })
export default { getSpecificModuleRedux, getPageList }


const reducerData = getSpecificModuleRedux('reducer')


const pickAB = pick<'1', 'general'>()(['a', 'b'])

pickAB({ a: 1, c: 3 })

Module type at'../module/module'

{
    app: {
        redux: {
            reducer: (state: Readonly<{
                theme: Readonly<{
                    readonly paletteType: "light" | "dark";
                }>;
            }> | undefined, action: IActionApp<any>) => {
                theme: {
                    paletteType: string;
                };
            };
        };
        page: {
            route: {
                path: string;
                exact: boolean;
                component: React.ComponentType<Overwrite<Setting.Props, StyledComponentProps<"root">>>;
                sidebarName: string;
                navBarName: string;
            };
        };
    };
    home: {
        page: {
            route: {
                path: string;
                exact: boolean;
                component: typeof ComponentName;
                sidebarName: string;
                navBarName: string;
            };
        };
    };
    todo: {
        page: {
            route: {
                path: string;
                exact: boolean;
                component: typeof ComponentName;
                sidebarName: string;
                navBarName: string;
            };
        };
    };
    sand: {
        page: {
            route: {
                path: string;
                exact: boolean;
                component: React.ComponentType<Overwrite<Sand.Props, StyledComponentProps<"root">>>;
                sidebarName: string;
                navBarName: string;
            };
        };
    };
}

Version

ts-node v6.1.0
node v8.9.4
typescript v2.9.1

"ramda": "^0.25.0",
 "@types/ramda": "types/npm-ramda#dist",

My source code is here: https://github.com/tomzaku/react-app-material-ts-boilerplate/blob/feature/addTheme/src/helper/module.ts
Thanks

-const listCompose = compose(removeUndefinedItem, getListData)
+const listCompose = compose(removeUndefinedItem, getListData<'1', 'list'>())

Looks like the same root cause as #386, TS chose the wrong overload (the 0-param one, which is the selectable overload) to infer types, so we need to manually specify which overload to use in this case, or you can simply write getListData(), which should choose the most general overload.