cem-tools: ExpandedType package - Could not expand union/intesection type

The expandedType properties does not get the final inferred type.

eg

type Size = 'small' | 'medium' | 'large';
type ChildSize =  Size | 'extra-small';

the ChildSize expandedType properties will output | 'extra-small' expecting it to be 'small' | 'medium' | 'large' | 'extra-small'

While doing intersecting, it would never show expandedType property.

type Size = 'small' | 'medium' | 'large';
type ChildSize =  Size & ('small' | 'medium' | 'extra-large');

Can use this Lit Component to replicate

import { html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';

/** The Size references. */
type Size = 'small' | 'medium' | 'large';

/** The Child Size references. */
type ChildSize =  Size | 'extra-small';

/**
 * The test element.
 * 
 * @example
 * ```html
 * <my-test size="small" child-size="extra-small">Content</my-test>
 * ```
 * 
 * @slot Default slot
 */
@customElement('my-test')
export class Test extends LitElement {
  /** The size. */
  @property() size?: Size = 'medium';

  /** The child size. */
  @property({attribute: 'child-size'}) childSize: ChildSize = 'extra-small';

  render() {
    return html`<div class=${classMap({
      test: true,
      [`test--${this.size}`]: true
    })}>
      <div class=${classMap({
        'test__child': true,
        [`test__child--${this.childSize}`]: true
      })}><slot></slot></div>
    </div>`
  }
}

Output custom-elements.json

{
  "schemaVersion": "1.0.0",
  "readme": "",
  "modules": [
    {
      "kind": "javascript-module",
      "path": "src/Test.ts",
      "declarations": [
        {
          "kind": "class",
          "description": "The test element.",
          "name": "Test",
          "slots": [
            {
              "description": "slot",
              "name": "Default"
            }
          ],
          "members": [
            {
              "kind": "field",
              "name": "size",
              "type": {
                "text": "Size | undefined"
              },
              "default": "'medium'",
              "description": "The size.",
              "attribute": "size",
              "expandedType": {
                "text": "'small' | 'medium' | 'large' | undefined"
              }
            },
            {
              "kind": "field",
              "name": "childSize",
              "type": {
                "text": "ChildSize"
              },
              "default": "'extra-small'",
              "description": "The child size.",
              "attribute": "child-size",
              "expandedType": {
                "text": " | 'extra-small'"
              }
            }
          ],
          "attributes": [
            {
              "name": "size",
              "type": {
                "text": "Size | undefined"
              },
              "default": "'medium'",
              "description": "The size.",
              "fieldName": "size",
              "expandedType": {
                "text": "'small' | 'medium' | 'large' | undefined"
              }
            },
            {
              "name": "child-size",
              "type": {
                "text": "ChildSize"
              },
              "default": "'extra-small'",
              "description": "The child size.",
              "fieldName": "childSize",
              "expandedType": {
                "text": " | 'extra-small'"
              }
            }
          ],
          "superclass": {
            "name": "LitElement",
            "package": "lit"
          },
          "tagName": "my-test",
          "customElement": true
        }
      ],
      "exports": [
        {
          "kind": "js",
          "name": "Test",
          "declaration": {
            "name": "Test",
            "module": "src/Test.ts"
          }
        },
        {
          "kind": "custom-element-definition",
          "name": "my-test",
          "declaration": {
            "name": "Test",
            "module": "src/Test.ts"
          }
        }
      ]
    }
  ]
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (13 by maintainers)

Most upvoted comments

Hmm the 1.2.0 still didn’t solve the issue for me. But i’ll try and setup an example repo as promised. Upd: see https://github.com/break-stuff/cem-tools/issues/84.

Thank you for your patience! Release 1.2.0 should resolve this issue. Let me know if you run into any problems.

Closing this for now. Let me know if there is anything else that comes up.

@arieffikhrie, I think I found the issue. I just deployed 1.1.2 (#27) and I think that should fix your issue. Let me know if you run into any issues.

Thank you for the great repro. Let me dig into it.