Code Monkey home page Code Monkey logo

Comments (4)

paoloricciuti avatar paoloricciuti commented on July 18, 2024

I suspect this has something to do with language-tools I'll try to take a look later

from svelte.

tommyminds avatar tommyminds commented on July 18, 2024

I found other cases where types are not generated anymore. There also seems to be an issue using ComponentProps for components that have a Snippet on their props. For example the following causes the outer component to not generate types anymore.

Outer.svelte

<script lang="ts">
	import type { ComponentProps } from 'svelte';
	import Inner from './Inner.svelte';
	let { foo }: ComponentProps<Inner> = $props();
</script>

Inner.svelte

<script lang="ts">
	import { type Snippet } from 'svelte';
	let {
		foo,
		footer
	}: {
		foo: string;
		footer?: Snippet;
	} = $props();
</script>

from svelte.

dummdidumm avatar dummdidumm commented on July 18, 2024

Investigating this. For some reason TypeScript seems to want to unpack the types when using the ComponentProps type, likely because of the infer used in there. That in combination with the generated d.ts output of the default export of components leads to TS breaking down somewhere. This not only happens for Snippet, it can happen for other imported types, too.
Not sure what a good fix could be yet.

from svelte.

dummdidumm avatar dummdidumm commented on July 18, 2024

Investigated this further. Ultimately this is a TypeScript limitation: For reasons that I don't understand TypeScript is not able to correctly backtrack imports if the declaration file is written of the form

declare module "svelte" {
  class Foo {}
  export { Foo }
}

TypeScript will then error with something like Exported variable 'X' has or is using name 'Foo' from external module "svelte" but cannot be named.
If the module is declared like this instead

declare module "svelte" {
  export class Foo {}
  export {}
}

The error does not appear. It seems that the extra indirection is too much for TypeScript to know where to find the import and then errors.

The fix is to revert Rich-Harris/dts-buddy#82 in dts-buddy and instead add export {} at the end, which has the same outcome with regards to which types can be imported.

from svelte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.