22/06/30 11:29:36.59 Argu0lpR.net
>>165
です。ありがとうございます。
実際のケースでお話しします。
・ライブラリの型を利用している。
・ライブラリの実装をそのまま真似ている。(実装は変えられる。)
・anyは使わない方針。
の状況です。
【型定義(サードパーティ)】
declare const visit: { <V extends Node>(tree: Node,test: Test<V> | Array<Test<any>>,visitor: visit.Visitor<V>,reverse?: boolean): void }
export = visit
declare namespace unistUtilIs {
type TestFunction<T extends Node> = (node: unknown,index?: number,parent?: Parent) => node is T
type Test<T extends Node> = TestFunction<T> | null | undefined }
【実装(大部分省略)】
import visit from 'unist-util-visit';
import { Node, Data } from 'unist';
function visitX(node: any): void {
if (!node.type) return;
}
return function transformer(tree): void {
visit(tree, (node: Node<Data>) => node.type === 'xxx', visitX);
};
ここで、function visitX(node: any) の Unexpected any. を消すのに難儀しています。
function visitX(node: Node<Data>): void {
にすると、
visit( の部分で
No overload matches this call.
Overload 1 of 2, '(tree: Node<Data>, test: any[] | Test<Node<Data>>, visitor: Visitor<Node<Data>>, reverse?: boolean | undefined): void', gave the following error.
...
と怒られます。極端な話、サードパーティの定義の方をいじらないと解決しないかもと思った次第です。