Skip to content

Commit a66c585

Browse files
Fix type checking
1 parent c83c0cb commit a66c585

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

src/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
// @ts-expect-error Type definitions don't know about createConfigItemSync
2-
import { transformAsync, createConfigItemSync } from '@babel/core';
3-
import type { VisitNodeObject, Node } from '@babel/traverse';
2+
import { transformAsync, createConfigItemSync, type PluginItem, type Visitor } from '@babel/core';
43
import { format, type Options as PrettierOptions } from 'prettier';
54

65
// @ts-expect-error We're only importing so we can create a config item, so we don't care about types
76
import bts from '@babel/plugin-transform-typescript';
87
const babelTsTransform = createConfigItemSync([
98
bts,
109
{ allowDeclareFields: true, onlyRemoveTypeImports: true },
11-
]);
10+
] as PluginItem);
1211

1312
// @ts-expect-error We're only importing so we can create a config item, so we don't care about types
1413
import bsd from '@babel/plugin-syntax-decorators';
15-
const babelDecoratorSyntax = createConfigItemSync([bsd, { version: 'legacy' }]);
14+
const babelDecoratorSyntax = createConfigItemSync([bsd, { version: 'legacy' }] as PluginItem);
1615

1716
export async function removeTypes(code: string, prettierConfig: PrettierOptions | boolean = true) {
1817
// Babel collapses newlines all over the place, which messes with the formatting of almost any
@@ -26,7 +25,7 @@ export async function removeTypes(code: string, prettierConfig: PrettierOptions
2625
// any comments that are associated with those constructs, since otherwise we'll be left with
2726
// comments that refer to something that isn't actually there.
2827
// Credit to https://github.com/cyco130/detype for figuring out this very useful pattern
29-
const removeComments: VisitNodeObject<unknown, Node> = {
28+
const removeComments: Visitor<unknown> = {
3029
enter(nodePath) {
3130
if (!nodePath.node.leadingComments) return;
3231

@@ -48,7 +47,7 @@ export async function removeTypes(code: string, prettierConfig: PrettierOptions
4847

4948
const transformed = await transformAsync(code, {
5049
plugins: [
51-
{
50+
() => ({
5251
name: 'comment-remover',
5352
visitor: {
5453
TSTypeAliasDeclaration: removeComments,
@@ -58,13 +57,13 @@ export async function removeTypes(code: string, prettierConfig: PrettierOptions
5857
TSImportType: removeComments,
5958
TSModuleDeclaration: removeComments,
6059
},
61-
},
60+
}),
6261
babelTsTransform,
6362
babelDecoratorSyntax,
6463
],
6564
generatorOpts: {
6665
retainLines: true,
67-
shouldPrintComment: (comment) => comment !== '___REMOVE_ME___',
66+
shouldPrintComment: (comment: string) => comment !== '___REMOVE_ME___',
6867
},
6968
configFile: false,
7069
});

0 commit comments

Comments
 (0)