dts-buddy icon indicating copy to clipboard operation
dts-buddy copied to clipboard

Incorrectly leaves `import` in place

Open benmccann opened this issue 1 year ago • 5 comments

https://github.com/sveltejs/kit/pull/9605 includes a line in navigation.js:

@type {(callback: (navigation: import('@sveltejs/kit').OnNavigate) => MaybePromise<(() => void) | void>) => void}

I believe this is incorrect. However, dts-buddy is still able to generate some output:

export const onNavigate: (callback: (navigation: import('@sveltejs/kit').OnNavigate) => MaybePromise<void | (() => void)>) => void;

I think the line in navigation.js should be updated to include import('types'):

@type {(callback: (navigation: import('@sveltejs/kit').OnNavigate) => import('types').MaybePromise<(() => void) | void>) => void}

If I do so then dts-buddy then generates:

export const onNavigate: (callback: (navigation: import('@sveltejs/kit').OnNavigate) => import('types').MaybePromise<(() => void) | void>) => void;
...
type MaybePromise<T> = T | Promise<T>;

It seems correct that dts-buddy then generates a type declaration for MaybePromise, but incorrect that it leaves the import('types') in place.

benmccann avatar Aug 17 '23 20:08 benmccann

Is this still happening? There were no typechecking issues on the PR after upgrading to the latest dts-buddy, does that mean this can be closed?

Rich-Harris avatar Aug 30 '23 17:08 Rich-Harris

I expect it is still happening if you revert the commit @s3812497 added to the PR that he was calling a workaround: https://github.com/sveltejs/kit/pull/9605/commits/c68d625f9494b01ae7c1497ea0b5cbe96561e270. I'm not sure exactly why that fixed it or if we want to say that's how you have to use it rather than calling it a workaround

benmccann avatar Aug 30 '23 20:08 benmccann

For some reason it couldn't resolve the 'types' path that was aliased in the package.json file. The relative path and exported @sveltejs/kit path seemed to be recognised instead.

eltigerchino avatar Aug 31 '23 00:08 eltigerchino

FYI I think this is fixed in the latest dts-buddy, though I haven't had a chance to check just yet

Rich-Harris avatar Nov 09 '23 01:11 Rich-Harris

https://github.com/sveltejs/kit/pull/11013

Rich-Harris avatar Nov 11 '23 19:11 Rich-Harris