dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.
MIT License
1.8k stars 100 forks source link

Correct mainFields type #217

Closed aaronadamsCA closed 2 years ago

aaronadamsCA commented 2 years ago

The type of mainFields is set to string[] in a few places, including the signature of createMatchPathAsync.

The correct type is (string | string[])[]:

https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/types.d.ts#L9767

This test case confirms the type is correct:

https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/test/TestCases.template.js#L149-L156

For type safety, it would be great if this package were compatible with the Webpack type of mainFields, foregoing the need for type assertions. Thanks!

aaronadamsCA commented 2 years ago

Here's the reason this syntax exists:

https://github.com/webpack/webpack/issues/7204#issuecomment-387843091

It's probably not very commonly used, but it'd still be good to be compatible with Webpack here.