emmm 讲真,没太看懂需求是什么,这个 title
是怎么来的?
我猜你是不是想要泛型:Playground Link
interface Token {
children: Token;
dom: HTMLElement;
key: string;
}
function iterate<T extends Token>(
tokenList: T[],
cb: (token: T) => void,
) {
return tokenList;
}
interface HeadingToken extends Token {
title: string;
}
const tokenList: HeadingToken[] = [];
iterate(tokenList, (token) => {
console.log(token.title);
});