-
Notifications
You must be signed in to change notification settings - Fork 83
New api generator discussion #26
Comments
Yeah, and I also have been meaning to revamp the API table style, any suggestions/screenshots are welcome. |
@Graphmaxer You've mentioned keeping the documentation in the I tested the project with typescript components and both I'd like to work on this if you have not already started something. I feel using this approach would be better because it provides both typing and documentation directly in the component file, thus reducing file juggling and documentation duplication. |
I agree with you @soft-decay, typescript is probably the good way to document components. I don't know any solution about the library usage, i think the svelte team is also figuring out the best way to distribute libraries with typings (RFC). And feel to free to experiment and try, i'm not working on this currently. |
Ok then, we have two approches:
Using the 1 method, this will be much better to maintain but we will need to also install typescript when doing an advanced install and I fear the development times would be slower (please correct me if I am wrong). Using the 2 method would be a lot easier but would not provide good definitions. I am personally inclined to the 1 method (we can also provide a custom preprocessor instead of using svelte-preprocess to speed things up?). Please list anything that I may have missed. |
@TheComputerM TL; DR I wanted 1 but I think 2 would work well in the meantime. I've encountered a few problems while experimenting.
Because of that, I think it would be best to :
Of course I do not know the full extend of what types you would like to provide, but I think jsdoc could be enough. It would be possible to update the |
So I worked on a declaration (d.ts) generator and I have a first working draft. I would like some input on how to improve it. Here's how it plugs into the
A small number of manually created declarations would have to be to kept in a separate folder for step 2.2. I spotted these:
You can check the changes I made in PR #76. |
I feel like storing all the components in a single |
Nice work here @soft-decay, I think that the Svelte team is changing to |
For sure I was not expecting this to be a permanent solution, just a way to reduce maintenance/effort on the typings in the short term. The new Should I go for it (same steps described above but with |
For the single file, go for it and for the usage of |
From what I tested, The bundled declarations file is over 2000 lines, but here is a snippet: import { SvelteComponentTyped } from 'svelte'
import { TransitionConfig, blur, crossfade, draw, fade, fly, scale, slide } from 'svelte/transition'
import { RippleOptions } from './@types/Ripple'
interface AlertProps {
class?: string;
/**
* @default true
*/
visible?: boolean;
transition?: any;
transitionOpts?: any;
/**
* @default false
*/
dense?: boolean;
/**
* @default false
*/
outlined?: boolean;
/**
* @default false
*/
text?: boolean;
/**
* @default false
*/
tile?: boolean;
/**
* @default false
*/
dismissible?: boolean;
/**
* @default false
*/
border?: boolean;
/**
* @default false
*/
coloredBorder?: boolean;
}
export declare class Alert extends SvelteComponentTyped<AlertProps> {} There is still a lot to be done for the component typings and documentation. What else would make it better and easier to use? I'm thinking adding events and slots. Right now |
Looks good to me ! Nice work @soft-decay ! 👍 We can also use the |
Also we have to parse events, slots and even sass variables (know any good way to do that?). |
|
This is better for sass https://github.com/mleg/sass-vars-to-js-example, @soft-decay we can customize the variables in svelte materiaify so it is needed to show what variables can be customized. |
@soft-decay You can see it here, should with default event/prop/slot. |
@Graphmaxer Are you referring to the 3rd generic param? That would be for slots, and the default keyword here refers to the default slot. You can also see it in the declaration. If that is not it, I'm sorry I could not see what you meant. @TheComputerM typed-scss-modules seems pretty good. I'll try it and see if it works well enough for the project's setup. |
@soft-decay Yes exactly, in this RFC, they also say :
this |
@Graphmaxer I see what you're saying, but my understanding is that it refers to the default slot, that is, the unnamed slot. For example : import { SvelteComponentTyped } from 'svelte';
export class MyComponent extends SvelteComponentTyped<{}, {}, { default: { numberProp: number } }> {} lets you do this (because the unnamed slot is the default slot) : <script lang="ts">
import { MyComponent } from "myModule";
</script>
<MyComponent let:numberProp>{{ numberProp }}</MyComponent> But this : import { SvelteComponentTyped } from 'svelte';
export class MyComponent extends SvelteComponentTyped<{}, {}, { content: { numberProp: number } }> {} Let you do this : <script lang="ts">
import { MyComponent } from "myModule";
</script>
<MyComponent>
<div slot="content" let:numberProp>{{ numberProp }}</div>
</MyComponent> In both case they would be typed as a |
@soft-decay You're right. I misunderstood this |
Hi, I'm plan to start implement the TS support in sveltedoc-parser (KatChaotic/sveltedoc-parser#34), but actually I dont use svelte with TS and it will be very nice if you have few examples with typescript svelte components |
Currently we are using sveltedoc-parser to generate JSON files that we can use in the website as API documentation.
Svelte is moving to Typescript and components too. Multiple options are available :
.svelte
file via comments. With thissveltedoc-parser
is fully functional with props/slots/events documentation..d.ts
files. We need to change the script to generate the JSON files. We can use native typescript compiler API, tsdoc parser, api-extractor or typedoc. With this option we can only type props until this get approved or similar.I started to implement a mix between sveltedoc-parser and typescript compiler api in this PR : #25.
Feel free to discuss about it.
The text was updated successfully, but these errors were encountered: