davestewart / alias-hq

The end-to-end solution for configuring, refactoring, maintaining and using path aliases
https://davestewart.co.uk/projects/open-source/alias-hq/
MIT License
330 stars 11 forks source link

Typescript fails to compile when get method's first parameter is not a string #61

Open meszaros-lajos-gyorgy opened 1 year ago

meszaros-lajos-gyorgy commented 1 year ago

The following line says that the method's first parameter is a string: https://github.com/davestewart/alias-hq/blob/main/src/index.js#L247

and vscode is yelling about it in my typescript project as expected: image

meszaros-lajos-gyorgy commented 1 year ago

I see the other type is also listed in the next line, but typescript doesn't recognise it as an overload

meszaros-lajos-gyorgy commented 1 year ago

My current workaround so far is:

import hq from 'alias-hq'

type TsOrJsConfig = {
  rootUrl: string
  baseUrl: string
  paths: Record<string, string[]>
}

type PluginCallback = (params: TsOrJsConfig) => any

const get = hq.get as (plugin: string | PluginCallback) => any

// ... use get instead of hq.get
davestewart commented 1 year ago

Hey there!

Sorry about that.

I should add type definitions (or migrate to TS) I suppose!

Let me look at that in the next couple of days.

davestewart commented 1 year ago

See: