Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package not generating .d.ts files for all components in new repo #3783

Closed
rgossiaux opened this issue Feb 9, 2022 · 5 comments
Closed

package not generating .d.ts files for all components in new repo #3783

rgossiaux opened this issue Feb 9, 2022 · 5 comments
Labels
pkg:svelte-package Issues related to svelte-package
Milestone

Comments

@rgossiaux
Copy link

Describe the bug

I set up a small test repo with Kit just now to demonstrate some other issue. All I did was create the repo with npm init svelte@next, npm install, npm install -D svelte2tsx typescript, create a few component files in src/lib, and create a src/lib/index.ts file.

For some reason when I run npm run package the component files Component.svelte, ComponentTwo.svelte, and ComponentThree.svelte don't have any .d.ts files generated in the package directory. Only Base.svelte.d.ts is generated. There are no errors or any other indications that something is wrong.

Reproduction

https://github.com/rgossiaux/svelte-typing-tests

npm install and npm run package

Logs

No response

System Info

System:
    OS: macOS 12.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 2.18 GB / 64.00 GB
    Shell: 3.3.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 16.8.0 - /var/folders/rn/2kdgb0jj25q2v656j3qc_ywr0000gn/T/fnm_multishells/23841_1640400023703/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 7.21.0 - /var/folders/rn/2kdgb0jj25q2v656j3qc_ywr0000gn/T/fnm_multishells/23841_1640400023703/bin/npm
  Browsers:
    Chrome: 98.0.4758.80
    Safari: 15.2
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.17
    @sveltejs/kit: next => 1.0.0-next.260
    svelte: ^3.44.0 => 3.46.4

Severity

blocking all usage of SvelteKit

Additional Information

No response

@rgossiaux
Copy link
Author

This evening I took a quick look into this. All the files are being passed into emitDts, but it looks like TypeScript is only calling host.writeFile for some of them.

I think it might be related to $$Generic, though without a root cause I'm not entirely sure. The three files that did not have emitted types all had $$Generic, and when I changed one of the types away from $$Generic in one of those components, its definition file was now emitted correctly.

@bluwy
Copy link
Member

bluwy commented Mar 3, 2022

I remember svelte2tsx's emitDts() function would silently fail if there are type errors in one of the components. I'm not sure if it's fixed yet though, but it may be the cause of this issue.

@rgossiaux
Copy link
Author

rgossiaux commented Mar 7, 2022

Ahhhhhhh... I figured it out! At least, partially. There's an issue because these components use the svelte.JSX namespace, but the package command does not load the svelte-jsx.d.ts file where this is defined (but svelte-check and the language server do, so there's no error otherwise).

If I add a config.svelteJsxPath, similar to the existing config.svelteShimsPath, to emitDts here:

https://github.com/sveltejs/language-tools/blob/05024a657784be7a5b57665f4cb39f8b649718a1/packages/svelte2tsx/src/emitDts.ts#L74

and here in kit:

svelteShimsPath: require.resolve('svelte2tsx/svelte-shims.d.ts'),

then we do get .d.ts files for ComponentTwo and ComponentThree.

Making this change also fixes the issue I reported at the bottom of this comment: sveltejs/language-tools#442 (comment) which is blocking me from shipping a big improvement to the TypeScript support for svelte-headlessui. I've been bashing my head against this for a while so I'm glad to have figured out what's wrong.

Does this sound like a reasonable fix? Maybe the svelte-native-jsx.d.ts file should be added as well (?).

cc @dummdidumm


edit: I think, separately from this particular fix, there should still be some error message if emitDts does not successfully emit a dts file.

@Ennoriel
Copy link

I have noticed the following:

All the following works:

type T = $$Generic;
type U = $$Generic<string>;

import type { TypeArbitrary } from './types.ts';
type V = $$Generic<TypeArbitrary >;

This does not work:

type TypeArbitrary = string;
type U = $$Generic<TypeArbitrary >;

It is as if defining a type used in a component as an extension of a generic type was not working.

@eltigerchino
Copy link
Member

Closing this as it is no longer reproducible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:svelte-package Issues related to svelte-package
Projects
None yet
Development

No branches or pull requests

5 participants