kit icon indicating copy to clipboard operation
kit copied to clipboard

enable suggestions for generated types `./$types`

Open eltigerchino opened this issue 2 years ago • 3 comments

Adds a path to the generated tsconfig.json file to resolve an import to .svelte-kit/types/src/routes/$types as ./$types.

Adding this path fixes a slight issue I've had with generated types where Quick Fix does not include './$types' as a suggestion.

Before: CleanShot 2022-09-07 at 21 00 43@2x

After: CleanShot 2022-09-07 at 21 03 29@2x

Sorry if this is unnecessary or implemented incorrectly. This is my first time submitting a PR.

Also, I tried to find a more variable that would lead to .svelte-kit/types/src/routes/ but the best I could find was config.outDir for .svelte-kit. Would appreciate if anyone knew a better path variable to use.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • [ ] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • [x] This message body should clearly illustrate what problems it solves.
  • [ ] Ideally, include a test that fails without this PR but passes with it.

Tests

  • [x] Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • [ ] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

eltigerchino avatar Sep 07 '22 13:09 eltigerchino

⚠️ No Changeset found

Latest commit: a5747ae69ef78a37f7685b16b9f84370ded9c767

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Sep 07 '22 13:09 changeset-bot[bot]

What do I have to do to get this to work? It's not showing up as a Quick Fix option for me:

image

Rich-Harris avatar Sep 21 '22 19:09 Rich-Harris

What do I have to do to get this to work? It's not showing up as a Quick Fix option for me:

image

The original paths that I used when testing this are as below.

"./types": [".svelte-kit/types/src/routes/$types", ".svelte-kit/types/src/routes/*/$types"],

Not sure if the config.outDir I used to replace the static path with is causing it to not work.

However, I've discovered that the generated types full path import does not show as a Quick Fix option in any files unless there's at least one import statement in a file referencing $types.

This also means TypeScript won't recognise the ./$types alias as it relies on the generated types existing and being added by TypeScript to the file watch.

Is it possible to get TypeScript to recognise the generated types without having to manually add the first import?

eltigerchino avatar Sep 21 '22 20:09 eltigerchino

Closing this, this was fixed inside TypeScript itself. I'm not sure which version this lands in, but either next month or in 4 months it'll work as expected.

dummdidumm avatar Oct 28 '22 19:10 dummdidumm