TS7006 — DedSec Project
TS7006 — implicit any conceals the callable contract Root cause TS7006 warns that a parameter has an implicit any type when noImplicitAny is active, typically via --strict. For example…
TS7006 — implicit any conceals the callable contract
Root cause
TS7006 warns that a parameter has an implicit any type when noImplicitAny is active, typically via --strict. For example, const convert = (value) => value + 1 cannot safely describe whether value should be a number or string; arithmetic and concatenation might behave differently. Merely turning off strict checking prevents this diagnostic without making the code reliable.
Reliable fix
Specify a function type (raw: string) => number and assign a callback to it. Contextual typing infers the callback parameter as string without writing the same annotation again. The example parses a port from a strictly digit-only string and verifies the value is an integer from 1 through 65535.
Verified TypeScript example
type Parser = (raw: string) => number;
const parsePort: Parser = (raw) => {
const port = Number(raw);
if (!/^[0-9]+$/.test(raw) || !Number.isInteger(port) || port < 1 || port > 65535)
throw new RangeError('port out of range');
return port;
};
if (parsePort('3000') !== 3000) throw Error();
try { parsePort('0'); throw Error('accepted invalid port'); }
catch (err) { if (!(err instanceof RangeError)) throw err; }
console.log('PASS TS7006');
Why it works
Contextual typing does not mean the runtime rejects invalid input automatically. The validation checks the original text, not only Number(raw), because Number('') yields zero. If the callback accepts untrusted network JSON, start with unknown and check it before invoking a typed parser; any bypasses this boundary.
Reproduction and build commands
Save as main.ts and run tsc --strict --target es2022 --module commonjs --outDir dist main.ts && node dist/main.js. In bad.ts write const convert = (value) => value + 1; and compile with tsc --strict --noEmit bad.ts. The expected diagnostic is TS7006.
Diagnostics to practice
Add a parser typed (input: unknown) => number and narrow its input before calling parsePort. Compare map((x) => x * 2) on a typed number array, where x is inferred, with an unannotated standalone function, where the contextual source is missing.
Reference: https://www.typescriptlang.org/tsconfig/noImplicitAny.html