Four TypeScript holes closed: method bivariance, constructors calling overrides, lists spread into variadic built-ins, optional properties #112
Loading…
Reference in a new issue
No description provided.
Delete branch "four-typescript-holes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stacked on #109 (the soundness corpus): this PR removes four lines from its list. Merge #109 first; I'll rebase this one onto
mainafterwards. It is independent of #110 and #111.Four programs that pass
tscin strict mode,safe-ts check --idiomaticand oxlint with the preset, with no cast and noany, and then fail at run time. Each gets a rule.1.
no-method-signature(error, with a quick fix)strictFunctionTypesdoes not apply to a member written as a method. The rule reports a method in an interface or type literal that has a parameter; the fix writesreadonly handle: (animal: Animal) => string. Measured withtsc: once the member is a property, an arrow, a method-shorthand literal and a class instance are all refused. A method with no parameters has nothing to vary and is left alone.safe-ts fix no-method-signature --writeconverted 48 sites in this repository.tscthen found one place that had only compiled because of the bivariance, in pack-kit, which is fixed.What it does not close, stated on the rule page: classes used as types (an override with a narrower parameter is still accepted) and the platform's own types (
Dog[]asAnimal[]).2.
constructor-calls-override(error)A constructor or field initializer that calls, directly or through the class's own methods, a method some subclass in the program overrides, or an abstract one. The override runs before the subclass's fields are set.
class extendsitself stays allowed. It needs the whole program, sosafe-ts checkreports it and the editor does not.3.
unbounded-spread(warning)Math.max(...values),target.push(...extra),String.fromCharCode(...codes): aRangeErrorpast roughly 100,000 elements, andMath.maxof nothing is-Infinity. Reported when the list's length is unknown; a literal, a tuple, a rest parameter andslice(0, 16)are fine, and so is a project type's own method that happens to be calledpush. std gainsmaxOfandminOf, which returnOption<number>.It is a warning, like
bounded-concurrencyandno-accumulating-copy: the limit takes a very long list to reach, and many sites are bounded by something the checker can't see.4.
no-optional-field(idiomatic, off by default)An optional property lets a value through whose real property has another type. With the idiomatic rules on,
key?: Tin a type the project declares is reported;key: Option<T>is what a value without the key is not assignable to. Exempt: optional parameters, types handed to the JSON validators, Vue and React props, types built on a library's, and declarations.What an adopter will notice
On an adopter's project (checked as directories, tests included):
no-method-signaturesafe-ts fixconstructor-calls-overrideunbounded-spreadno-optional-fieldIn a sample of 13
unbounded-spreadfindings outside tests, nine wereMath.maxorMath.minwith the empty-list trap, and one was a live bug: a guard that returnsInfinitywhen its list is empty. About five were bounded in practice.How it was checked
test:std(381),typecheck, the docs examples,test:vite, the docs site build and the soundness corpus pass..map).this-typed methods and their implementers;tscpasses before and after.push, and aconstholdingslice(0, 3).Not done
no-optional-fieldhas no quick fix: it needs the whole program, andsafe-ts fixworks a file at a time.Math.maxis not reported; the empty case would need its own finding.Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review, acceptance tests, and the warning level) in Claude Code.
5c95a1359cb8ca7a1819as#113