Skip to content

Commit 1c37d81

Browse files
committed
feature: @putout/plugin-typescript: apply-type-guards: exists
1 parent dd64ad0 commit 1c37d81

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const isNumber = (a): a is number => typeof a === 'number';

packages/plugin-typescript/lib/apply-type-guards/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const create = template('(__a): __a is __c => typeof __a === "__b"', {
1515

1616
module.exports.report = () => `Use 'type guards'`;
1717

18+
module.exports.match = () => ({
19+
'(__a) => typeof __a === "__b"': ({}, path) => !path.node.returnType,
20+
});
21+
1822
module.exports.replace = () => ({
1923
'(__a) => typeof __a === "__b"': ({__a, __b}, path) => {
2024
replaceWith(path, create({

packages/plugin-typescript/lib/apply-type-guards/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ test('plugin-apply-guards: transform: apply-type-guards', (t) => {
1818
t.transform('apply-type-guards');
1919
t.end();
2020
});
21+
22+
test('plugin-apply-guards: no report: exists', (t) => {
23+
t.noReport('exists');
24+
t.end();
25+
});

0 commit comments

Comments
 (0)