Skip to content

Commit

Permalink
fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed Jul 15, 2020
1 parent b0adf5e commit 9a1ace1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SimpleType, SimpleTypeKind, toTypeString } from "ts-simple-type";
import { SimpleType, typeToString } from "ts-simple-type";
import { HtmlNodeAttr } from "../../../analyze/types/html-node/html-node-attr-types";
import { RuleModuleContext } from "../../../analyze/types/rule/rule-module-context";
import { rangeFromHtmlNodeAttr } from "../../../analyze/util/range-util";
Expand All @@ -10,14 +10,14 @@ export function isAssignableInEventBinding(
context: RuleModuleContext
): boolean | undefined {
const expectedType: SimpleType = {
kind: SimpleTypeKind.FUNCTION,
returnType: { kind: SimpleTypeKind.VOID },
argTypes: [
kind: "FUNCTION",
returnType: { kind: "VOID" },
parameters: [
{
name: 'event',
name: "event",
type: typeA,
optional: false,
spread: false,
rest: false,
initializer: false
}
]
Expand All @@ -26,7 +26,7 @@ export function isAssignableInEventBinding(
if (!isAssignableToType({ typeA: expectedType, typeB }, context)) {
context.report({
location: rangeFromHtmlNodeAttr(htmlAttr),
message: `Type '${toTypeString(typeB)}' is not assignable to '${toTypeString(expectedType)}'`
message: `Type '${typeToString(typeB)}' is not assignable to '${typeToString(expectedType)}'`
});

return false;
Expand Down
25 changes: 17 additions & 8 deletions packages/lit-analyzer/test/rules/no-incompatible-type-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,30 @@ html\`<input step="\${myDirective("foo")}" /> \`
hasDiagnostic(t, diagnostics, "no-incompatible-type-binding");
});

test("Event binding: event handler is assignable to valid event", t => {
const { diagnostics } = getDiagnostics([makeElement({ events: ["foo-event"] }), 'html`<my-element @foo-event=${(ev) => {}}></my-element>`']);
tsTest("Event binding: event handler is assignable to valid event", t => {
const { diagnostics } = getDiagnostics([makeElement({ events: ["foo-event"] }), "html`<my-element @foo-event=${(ev) => {}}></my-element>`"]);
hasNoDiagnostics(t, diagnostics);
});

test("Event binding: event handler is assignable to valid typed event", t => {
const { diagnostics } = getDiagnostics([makeElement({ events: ["{MouseEvent} foo-event"] }), 'html`<my-element @foo-event=${(ev: MouseEvent) => {}}></my-element>`']);
tsTest("Event binding: event handler is assignable to valid typed event", t => {
const { diagnostics } = getDiagnostics([
makeElement({ events: ["{MouseEvent} foo-event"] }),
"html`<my-element @foo-event=${(ev: MouseEvent) => {}}></my-element>`"
]);
hasNoDiagnostics(t, diagnostics);
});

test("Event binding: invalid event handler is not assignable to typed event", t => {
const { diagnostics } = getDiagnostics([makeElement({ events: ["{MouseEvent} foo-event"] }), 'html`<my-element @foo-event=${(ev: KeyboardEvent) => {}}></my-element>`']);
tsTest("Event binding: invalid event handler is not assignable to typed event", t => {
const { diagnostics } = getDiagnostics([
makeElement({ events: ["{MouseEvent} foo-event"] }),
"html`<my-element @foo-event=${(ev: KeyboardEvent) => {}}></my-element>`"
]);
hasDiagnostic(t, diagnostics, "no-incompatible-type-binding");
});

test("Event binding: invalid event handler is not assignable to event", t => {
const { diagnostics } = getDiagnostics([makeElement({ events: ["foo-event"] }), 'html`<my-element @foo-event=${(arg: boolean) => {}}></my-element>`']);
tsTest("Event binding: invalid event handler is not assignable to event", t => {
const { diagnostics } = getDiagnostics([
makeElement({ events: ["foo-event"] }),
"html`<my-element @foo-event=${(arg: boolean) => {}}></my-element>`"
]);
});

0 comments on commit 9a1ace1

Please sign in to comment.