Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/runtime-class/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,15 @@ declare global {
export interface NativeTag<
Input extends Record<string, any>,
Return extends Element,
Value = never,
> {
input: Input;
return: { value: () => Return };
return: {
value: (() => Return) & Value;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I came back and checked out the actual runtime behavior and it appears that <style/foo> produces a module namespace object. In hindsight, this isn't surprising at all. That's exactly what the docs say:

If the <style> tag has a Tag Variable, it leverages CSS Modules to expose its classes as an object.

Which suggests that the following should be mutually exclusive:

<style/> /* () => HTMLStyleElement */
<style/binding/> /* Record<string, string> */

And even that isn't quite right. The runtime representation of CSS modules may be tooling-dependent. I'm struggling to find this now in the docs, but unless I'm mistaken, I remember reading that this is deferred to the bundler. In any case, what I see with my (mostly) out-of-the-box project (Marko 6 + Marko Run + Vite) is an interface more like:

interface CSSModule {
  [key: string]: string;
  default: Record<string, string>;
}

(That's not actually a valid type definition, but hopefully it gets the point across.)

Anyway... all of this is a long way around the barn to say:

  1. I'm even more doubtful that these types are right.
  2. I'm actually kind of doubtful that static type definitions are even the right place to solve this!

On Discord, @DylanPiercey also mentioned interest in special casing CSS module typegen in the Marko language server. That sounds like it would produce more appealing types in the first place... it would certainly be better than this change in its current state.

I'll defer to the Marko team on whether this PR is worth pursuing any further. But it does feel pretty iffy to me, and I won't mind at all if y'all close it for now in lieu of a more robust/fitting solution.

};
}
export interface NativeTags {
[name: string]: NativeTag<Record<string, any>, Element>;
[name: string]: NativeTag<Record<string, any>, Element, any>;
}

export type Input<Name> = 0 extends 1 & Name
Expand Down
6 changes: 5 additions & 1 deletion packages/runtime-class/tags-html.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ declare global {
source: NativeTag<Marko.HTML.Source, HTMLSourceElement>;
span: NativeTag<Marko.HTML.Span, HTMLSpanElement>;
strong: NativeTag<Marko.HTML.Strong, HTMLElement>;
style: NativeTag<Marko.HTML.Style, HTMLStyleElement>;
style: NativeTag<
Marko.HTML.Style,
HTMLStyleElement,
Record<string, string>
>;
sub: NativeTag<Marko.HTML.Sub, HTMLElement>;
summary: NativeTag<Marko.HTML.Summary, HTMLElement>;
sup: NativeTag<Marko.HTML.Sup, HTMLElement>;
Expand Down
7 changes: 5 additions & 2 deletions packages/runtime-tags/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ declare global {
export interface NativeTag<
Input extends Record<string, any>,
Return extends Element,
Value = never,
> {
input: Input;
return: { value: () => Return };
return: {
value: (() => Return) & Value;
};
}
export interface NativeTags {
[name: string]: NativeTag<Record<string, any>, Element>;
[name: string]: NativeTag<Record<string, any>, Element, any>;
}

export type Input<Name> = 0 extends 1 & Name
Expand Down
6 changes: 5 additions & 1 deletion packages/runtime-tags/tags-html.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ declare global {
source: NativeTag<Marko.HTML.Source, HTMLSourceElement>;
span: NativeTag<Marko.HTML.Span, HTMLSpanElement>;
strong: NativeTag<Marko.HTML.Strong, HTMLElement>;
style: NativeTag<Marko.HTML.Style, HTMLStyleElement>;
style: NativeTag<
Marko.HTML.Style,
HTMLStyleElement,
Record<string, string>
>;
sub: NativeTag<Marko.HTML.Sub, HTMLElement>;
summary: NativeTag<Marko.HTML.Summary, HTMLElement>;
sup: NativeTag<Marko.HTML.Sup, HTMLElement>;
Expand Down