## As is `@d-zero/csstree-scss-syntax` と `@d-zero/stylelint-rules` は、実行時には `css-tree@3.2.1` を使うが、型は `@types/css-tree@2.3.11`(css-tree 2 向けの型)で検査している。 以前はこの型を宣言しておらず、markuplint v4 の依存として入っていた `@types/css-tree@2.3.11` に頼っていた。markuplint v5(`@markuplint/types@5.4.0`)が `@types/css-tree@^3.2.0` を持ち込んだため、両パッケージの devDependencies に `@types/css-tree@2.3.11` を明示的に宣言して型を固定した。 `@types/css-tree@3.2.0` で型検査すると、`yarn lint:tsc` が次で落ちる: - `packages/@d-zero/csstree-scss-syntax/src/types.ts:25`: `Interface 'LexerEx' incorrectly extends interface 'Lexer'`(`matchProperty` の戻り値の `matched.match` の要素が `SyntaxMatchNode` と非互換。`node` が `null` を取りうる) - `packages/@d-zero/csstree-scss-syntax/src/types.ts:31`: `Interface 'LexerMatchResultMatched' incorrectly extends interface 'LexerMatchResult'`(同じ理由) - `packages/@d-zero/stylelint-rules/src/utils/get-value-type.ts:71`: `'props.match' is possibly 'undefined'` Renovate が `@types/css-tree` 3 の PR を作ると、移行するまで CI が落ちる。 ## To be 型が実行時の css-tree 3 と一致する。`@types/css-tree` を 3 系にしても `yarn lint:tsc` が通る。 ## Why - 実行時のライブラリと型定義のメジャーバージョンがずれていると、型検査が実際の API と違うものを検証することになる - css-tree 3 の型: `@types/css-tree@3.2.0` ## How - `packages/@d-zero/csstree-scss-syntax/src/types.ts` の `LexerEx` / `LexerMatchResultMatched` / `LexerMatchResultMismatch` を、`@types/css-tree@3` の `Lexer` / `LexerMatchResult` / `SyntaxMatchNode` に合わせて定義し直す(`node` が `null` を取りうる点など) - `packages/@d-zero/stylelint-rules/src/utils/get-value-type.ts:71` で `props.match` が `undefined` の場合を扱う - 両パッケージの devDependencies の `@types/css-tree` を 3 系に上げる。`css-tree` と `@types/css-tree` は片方だけ上げると型検査が通らない組なので、`.github/renovate.json` で同じ groupName にまとめるかを判断する - 利用側への影響: 型定義の内部の変更で、公開 API と実行時の振る舞いは変わらない(breaking ではない)
Activity