tfs-tada / eslint-plugin-no-excess-property

ESLint plugin to prevent excess properties in TypeScript objects, ensuring strict adherence to type definitions.
https://www.npmjs.com/package/eslint-plugin-no-excess-property?activeTab=readme
MIT License
3 stars 0 forks source link

fix: array checker #23

Open tfs-tada opened 3 weeks ago

tfs-tada commented 3 weeks ago
 type User = { name: string };
 const taro = { name: "taro" };
 const jiro = { name: "jiro", age: 10 };
 const saburo = { name: "saburo" };
 const users: User[] = [taro, jiro, saburo];
tfs-tada commented 1 week ago

🗓️ ts.Nodeの段階で ts.isArrayLiteralExpression の絞り込み -> node.elements で取得可能だが、checker内で処理できるかは不明

const initNode = parserServices.esTreeNodeToTSNodeMap.get(node.init);
const initTypes = ts.isArrayLiteralExpression(initNode)
  ? initNode.elements.map(
      (e) => [e, checker.getTypeAtLocation(e)] as const,
    )
  : ([[node, checker.getTypeAtLocation(initNode)]] as const);

const idType = checker.getElementTypeOfArrayType(
  checker.getTypeAtLocation(
    parserServices.esTreeNodeToTSNodeMap.get(node.id),
  ),
);