sheerun / prettier-standard

Formats with Prettier and lints with ESLint+Standard! (✿◠‿◠)
MIT License
868 stars 44 forks source link

there is a format question in typescript file #111

Open taomas opened 3 years ago

taomas commented 3 years ago

error stack

src/helpers/cookie.ts 14ms
TypeError: Cannot read property 'map' of undefined
    at Converter.convertNode (/<path>/node_modules/prettierx/node_modules/@typescript-eslint/typescript-estree/dist/convert.js:1225:64)
    at Converter.converter (/<path>/node_modules/prettierx/node_modules/@typescript-eslint/typescript-estree/dist/convert.js:72:29)
    at Converter.convertChild (/<path>/node_modules/prettierx/node_modules/@typescript-eslint/typescript-estree/dist/convert.js:144:21)
    at /<path>/node_modules/prettierx/node_modules/@typescript-eslint/typescript-estree/dist/convert.js:200:32
    at Array.map (<anonymous>)
    at Converter.convertBodyExpressions (/<path>/node_modules/prettierx/node_modules/@typescript-eslint/typescript-estree/dist/convert.js:199:14)
    at Converter.convertNode (/<path>/node_modules/prettierx/node_modules/@typescript-eslint/typescript-estree/dist/convert.js:433:32)
    at Converter.converter (/<path>/node_modules/prettierx/node_modules/@typescript-eslint/typescript-estree/dist/convert.js:72:29)
    at Converter.convertProgram (/<path>/node_modules/prettierx/node_modules/@typescript-eslint/typescript-estree/dist/convert.js:47:21)
    at Object.astConverter (/<path>/node_modules/prettierx/node_modules/@typescript-eslint/typescript-estree/dist/ast-converter.js:25:29)
error Command failed with exit code 2.

i found the error is appear when export syntax.

this is the error code

import { isEqual } from 'lodash'
import { useState, useCallback } from 'react'
export interface IProps<U> {
  bodyParams: U | any
  queryParams?: U | any
}
export interface IParams<T> {
  bodyParams?: T
  queryParams?: T
}
export interface IOptions {
  isLoading?: boolean
}

export interface IRespoense {
  code: number
  data: any
  errInfos: any
  errorCode: number
  msg: string
  ret: number
}
function useLazyRequest<T = any> (
  request: any,
  options?: IOptions
): [boolean, any, (runParams?: T) => Promise<void>] {
  const [loading, setloadding] = useState(true)
  const [data, setdata] = useState(null)
  const run = useCallback(
    async runParams => {
      options.isLoading && setloadding(true)
      request(runParams)
        .then((res: IRespoense) => {
          if (!isEqual(res, data)) setdata(res)
        })
        .catch((err: Error) => {
          console.log(err)
        })
        .finally(() => {
          options.isLoading && setloadding(false)
        })
    },
    [data, loading]
  )
  return [loading, data, run]
}
export default useLazyRequest

how to fix the error ?

starpit commented 3 years ago

I suspect that this is because prettierx 0.11.3 is using an old version of @typescript-eslint/typescript-estree (2.6.1) which is not compatible with typescript 4+.

the latest version of @typescript-eslint/typescript-estree is 4.15.1 the latest version of prettierx is 0.17.0

prettier-standard has hard-wired this older version of prettierx:


{
    "prettierx": "0.11.3"                                                                                                      
}