From 9251644d336d57085ae56e6d1a757d058b02300d Mon Sep 17 00:00:00 2001 From: Andrew Jakubowicz Date: Fri, 12 Jan 2024 15:16:22 -0800 Subject: [PATCH] attempt to repro an enum bug --- .../rules/no-incompatible-type-binding.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/lit-analyzer/src/test/rules/no-incompatible-type-binding.ts b/packages/lit-analyzer/src/test/rules/no-incompatible-type-binding.ts index c7cc6226..d006f3d6 100644 --- a/packages/lit-analyzer/src/test/rules/no-incompatible-type-binding.ts +++ b/packages/lit-analyzer/src/test/rules/no-incompatible-type-binding.ts @@ -217,6 +217,34 @@ tsTest("Property binding: Boolean type expression is not assignable to boolean p hasNoDiagnostics(t, diagnostics); }); +tsTest("Property binding: String union type is assignable in property binding", t => { + const { diagnostics } = getDiagnostics(` + +class MyElement extends LitElement { + enumProp: 'opt1' | 'opt2'; + static override properties = { + enumProp: {type: String, reflect: true}, + }; + constructor() { + super(); + this.enumProp = 'opt1'; + } +}; +customElements.define("my-element", MyElement); + +class MyElement2 extends LitElement { + @property({attribute: false}) + matchingEnum: 'opt1' | 'opt2' = 'opt2'; + + override render() { + return html\`\`; + } +}; +customElements.define("my-element2", MyElement2); +`); + hasNoDiagnostics(t, diagnostics); +}); + tsTest("Attribute binding: 'ifDefined' directive correctly removes 'undefined' from the type union 1", t => { const { diagnostics } = getDiagnostics('type ifDefined = Function; html``'); hasNoDiagnostics(t, diagnostics);