Skip to content

<style> as Tag Variable lacks types for class properties #2775

@eyelidlessness

Description

@eyelidlessness

Marko Version: 6.0.50

Details

As described in the docs for <style>:

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

In my usage, I've found this works at build/runtime, but I see TypeScript type errors (at least in VSCode) when accessing those properties. For instance, in this snippet from the documented example:

<style/styles>
  .foo {
    border: 1px solid red;
  }
</style>

<div class=styles.foo/>
//                ^ Property 'foo' does not exist on type '() => HTMLStyleElement'

Expected Behavior

Ideally: since <style> as a Tag Variable is compiled as a CSS module, it would be very nice if the specific exports were exposed in generated types.

Pragmatically: it makes sense that the <style> Tag Variable's type could be expressed as Record<string, string> (perhaps as an intersection with () => HTMLStyleElement?).

Actual Behavior

As above, accessing properties on the <style>'s Tag Variable produces TypeScript type errors.

(Well, to be pedantic… since the variable is typed as a function, accessing a function's properties does not produce type-level errors. I haven't checked the runtime behavior for that, but I could imagine…!)

Possible Fix

I'll open a PR shortly!

Additional Info

Your Environment

  • Environment name and version (e.g. Chrome 39, node.js 5.4): N/A. More applicable: I observe the issue in VSCode
  • Operating System and version (desktop or mobile): N/A
  • Link to your project: I actually don't have one yet! I just started playing with Marko this morning. 😅 But I see the same issue in this repo, i.e. this fixture.

Steps to Reproduce

  1. Create a Marko template with <style> as a Tag Variable (or use the fixture linked above)
  2. Open the template in an editor configured to check TypeScript types in Marko

Stack Trace

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:unverified bugA bug report that has not been verified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions