Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e99ca81

Browse files
ldrickbradzacher
authored andcommitted
fix(eslint-plugin): support switch statement [unbound-method] (typescript-eslint#485)
1 parent 52944bd commit e99ca81

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/eslint-plugin/src/rules/unbound-method.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ function isSafeUse(node: TSESTree.Node): boolean {
9797
case AST_NODE_TYPES.IfStatement:
9898
case AST_NODE_TYPES.ForStatement:
9999
case AST_NODE_TYPES.MemberExpression:
100+
case AST_NODE_TYPES.SwitchStatement:
100101
case AST_NODE_TYPES.UpdateExpression:
101102
case AST_NODE_TYPES.WhileStatement:
102103
return true;

packages/eslint-plugin/tests/rules/unbound-method.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ instane.boundStatic && 0;
9898
ContainsMethods.boundStatic ? 1 : 0;
9999
ContainsMethods.unboundStatic ? 1 : 0;
100100
`,
101+
`interface RecordA {
102+
readonly type: "A"
103+
readonly a: {}
104+
}
105+
interface RecordB {
106+
readonly type: "B"
107+
readonly b: {}
108+
}
109+
type AnyRecord = RecordA | RecordB
110+
111+
function test(obj: AnyRecord) {
112+
switch (obj.type) {
113+
}
114+
}`,
101115
],
102116
invalid: [
103117
{

0 commit comments

Comments
 (0)