-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add event bindings to incompatible type binding rule
- Loading branch information
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/lit-analyzer/src/rules/util/type/is-assignable-in-event-binding.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { SimpleType, SimpleTypeKind, toTypeString } 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"; | ||
import { isAssignableToType } from "./is-assignable-to-type"; | ||
|
||
export function isAssignableInEventBinding( | ||
htmlAttr: HtmlNodeAttr, | ||
{ typeA, typeB }: { typeA: SimpleType; typeB: SimpleType }, | ||
context: RuleModuleContext | ||
): boolean | undefined { | ||
const expectedType: SimpleType = { | ||
kind: SimpleTypeKind.FUNCTION, | ||
returnType: { kind: SimpleTypeKind.VOID }, | ||
argTypes: [ | ||
{ | ||
name: 'event', | ||
type: typeA, | ||
optional: false, | ||
spread: false, | ||
initializer: false | ||
} | ||
] | ||
}; | ||
|
||
if (!isAssignableToType({ typeA: expectedType, typeB }, context)) { | ||
context.report({ | ||
location: rangeFromHtmlNodeAttr(htmlAttr), | ||
message: `Type '${toTypeString(typeB)}' is not assignable to '${toTypeString(expectedType)}'` | ||
}); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters