zkochan / packages

Zoltan Kochan's npm packages
MIT License
99 stars 26 forks source link

[which-pm] [bug] Return type does not contain `null` #175

Open sounisi5011 opened 1 year ago

sounisi5011 commented 1 year ago

https://github.com/zkochan/packages/blob/6da32f07fb3592675505b77724e8e4fd17afaa34/which-pm/index.d.ts#L1

https://github.com/zkochan/packages/blob/6da32f07fb3592675505b77724e8e4fd17afaa34/which-pm/index.d.ts#L4

In this type declaration, the return type is defined as Promise<whichpm.NPM | whichpm.YARN | whichpm.PNPM | whichpm.Other>.

However, according to the actual code, this function could return null.

https://github.com/zkochan/packages/blob/6da32f07fb3592675505b77724e8e4fd17afaa34/which-pm/index.js#L19

Therefore, the correct return type is Promise<whichpm.NPM | whichpm.YARN | whichpm.PNPM | whichpm.Other | null>.

This type declaration should add null to the type whichpm.Result.

-   type Result = NPM | YARN | PNPM | Other
+   type Result = NPM | YARN | PNPM | Other | null

Or, should add null to the return type.

- declare function whichpm (pkgPath: string): Promise<whichpm.Result>
+ declare function whichpm (pkgPath: string): Promise<whichpm.Result | null>