概要
以下の警告によく出会う。
Parameter 'val' implicitly has an 'any' type, but a better type may be inferred from usage. [7044]
暗黙anyだけど、もっと良い型ありそう〜って言ってる。
ミス
TSに不慣れなもので当てずっぽうに型を明示するが、
一向に直らない。
const copy = input.split('').filter(val => !isNaN(Number(val))).join(''); ↓ const copy = input.split('').filter(val: string => !isNaN(Number(val))).join('');
正解
型を明示する際は、アロー関数の変数を()括弧で囲む必要がある。
const copy = input.split('').filter((val: string) => !isNaN(Number(val))).join('');
これ、よく忘れる。。。