What quick fixes keep
Every editor quick fix, safe-ts fix <rule> run, and safe-ts migrate codemod either preserves exact runtime behavior or states explicitly in its title what changes. Silently altering runtime behavior while staying compile-clean is treated as a bug—and guarded by an automated fix-meaning test suite.
In short
(the same as now): identical output for every input (undefined,null,"",0,NaN,0n,false).- Explicit behavior changes: titles name the exact edge case that shifts (e.g. Compare with 0 (NaN counts as true) or Use ?? (only for undefined)).
- Type-only edits: annotation updates (
unknown,Option<T>,Mut<T>) leave runtime execution untouched.
Two earlier bugs motivated this contract: in 0.2.0 null-to-undefined rewrote === null on external data into a permanently false === undefined, and in 0.4.0 a strict-truthiness fix produced unitId !== "" on an optional string (matching undefined). Both cases now run in CI across every quick fix and codemod.
safe-ts fix <rule> takes a fix marked (the same as now) by itself where a site has several and exactly one says so; any other fix it applies only where it is the site's only one or --fix picks it (Applying one rule's quick fixes).
How to read a title
- "(the same as now)": every input gives the same result as before:
undefined,nullwhere the type has it,"",0,NaN,0n,false. - The title names what changes: Test for undefined only (
""counts as true), Compare with 0 (NaN counts as true), Use ?? (only for undefined), Compare with undefined (was always false), Wrap in unsafe(() => …): returns a Result you must check. Only those inputs, or only that part of the behaviour, change. - Types only: Replace any with unknown, Write as Option<...>, Declare that this function changes
x: Mut<…>. Nothing runs differently.
NaN counts as false in a test (if (count)), and no comparison with 0 says so: the fixes for a number name it. A value read through a call (items.shift(), map.get(k)) is read once by the fix ((items.shift() ?? "") !== ""), since a second call can give another value.
Every quick fix
| Rule | Fix | What it does to the result |
|---|---|---|
strict-truthiness | Test for undefined and "" / 0n (the same as now) | the same |
| Test for undefined and 0 (NaN counts as true) | NaN now passes | |
| Test for undefined only (… counts as true) | "", 0, NaN, 0n now pass | |
Compare with "" / Compare with 0n | the same | |
| Compare with 0 (NaN counts as true) | NaN now passes | |
| Test for a positive number | negative numbers now fail | |
| Spread the items that are kept | the same (with (NaN counts as true) when a number is tested) | |
compare-misses-undefined | Let undefined pass (the same as now), Test for "" only (the same as now) | the same |
Make undefined fail too, Treat undefined as "" | undefined changes branch | |
prefer-is-over-tag, prefer-constructor-tag | Use is(x, "Red"), Use Light.Red | the same; is(x, …) isn't offered on a value declared with null, which is doesn't take |
exhaustive-switch | Add default: unreachable(…) | the same for every variant |
no-ts-enum | Convert to a const object + union type | the same values; not offered for a numeric enum read as an object here (Color[0], Object.keys(Color)) |
no-null-check-for-undefined | Compare with undefined (the same as now) | the same (== null already passed for undefined) |
| Compare with undefined (was always false / true), (the assertion always failed / passed), Use toBeUndefined() … | the test now tests for undefined | |
no-undefined-check-for-null | Compare with null: … (the same as now) | the same |
| Compare with null: … (was always false / true) | the test now tests for null | |
prefer-nullish-default | Use ?? (only for undefined), Use ??= | "", 0, NaN, false keep their value |
prefer-q, needs-transform | Use const x = q(...), Write it without q, Import … | the same |
must-use-result | Discard explicitly with void | the same |
| Propagate the error with q(…) | the error is now returned | |
unhandled-failure, no-throw, number-parse-nan, floating-rejection | Wrap in unsafe(…), Use the safe version, which returns a Result, Return err(…) instead of throwing, Add await, … | the failure becomes a value, or is handled, as the title says |
no-param-mutation | Use toSorted(), Use toReversed(), Update a copy | the same result; the caller's value is no longer changed. Update a copy only for a plain object's type declared in the file |
readonly-dropped | Keep it read-only: Readonly<…> | the same: only the annotation changes; a write through it, which threw on the frozen value, is now refused by TypeScript |
missing-mut, unneeded-mut | Lend it: mut(x), Pass it as it is: remove mut(…) | the same: mut(x) is x (the transform erases it); only what TypeScript accepts changes |
sort-comparator | Sort numerically | numbers sort as numbers |
dataview-endianness | Big-endian (false, the default) / Little-endian (true) | the same / the other byte order |
hoist-intl | Create it once | the same |
keep-error-cause, no-for-in | Keep e as the cause, Iterate own keys | the error gets a cause; inherited keys are left out |
no-type-predicate, brand-constructor | Let TypeScript infer the narrowing from the body | the same at runtime: only : x is T goes, and TypeScript infers the predicate from the body. Where the claim said more than the body tests, the code that relied on it stops compiling |
no-ts-suppression | Use @ts-expect-error | the same: a comment; TypeScript now reports it once the error is gone |
no-method-signature | Write handle as a readonly property with a function type | the same: only types; tsc then refuses an implementation whose parameter is narrower, and a reassignment of the member (drop readonly there) |
no-hidden-any | Write MessageEvent<unknown>, Replace Function with (...args: never[]) => unknown, Annotate event: MessageEvent<unknown>, Annotate value: unknown | the same: only types; tsc then reports each use that reads the value unchecked |
unused-code, unused-private | Delete name | nothing referred to it: what runs is the same. safe-ts fix unused-code <dirs> applies it to the whole program at once |
unbound-method | Bind it: this.tick.bind(this) (keeps this when it runs) | the method runs on its object: what threw TypeError (this undefined) works |
stale-across-await | Await first: const awaited = await …; then x += awaited | the read moves after the await: a call that ran meanwhile is no longer lost (with one call at a time, the same) |
unreleased-resource | Release it in a finally | the same result; the release now runs on every way out of the block |
unbalanced-update | Undo it in a finally | changes what the code does on purpose: the undo now runs on the way out that skipped it (the count is given back, the flag cleared); the result is the same otherwise |
The Vue fixes (Add .value, Watch a getter, Use shallowRef, …) change what the component reads, as their titles say; they aren't run by the test below, which runs plain TypeScript.
How it is checked
crates/safe_ts_core/tests/meaning.rs writes small functions whose tested value is typed each way: T, T | undefined, x?: T, Option<T>, T | null, a field, a type from another file, a?.b, a call that changes state, and a function from another file, for strings, numbers, bigints and enums. It applies every fix the way safe-ts fix --fix "<title>" does, type-checks the code before and after, runs both in Node after the build-time transform over every value the type allows, and fails when a result changes where the title doesn't say so, or when the rule still reports the fixed code. Programs where a fix would change the result (splice to toSpliced, an array spread into an object) must not get it. A fix whose title isn't in its table fails the test too, also when it shows up in a fixture, and so does a title that says (the same as now) where the table doesn't say the result stays the same.
The codemods are checked the same way: each runnable case in tests/migrate/ has a probe.mjs, calls run on the code before and after the codemod. A thrown error and a returned Err of it count as the same failure; after null-to-undefined, a caller's null is passed as undefined, and data from JSON or the DOM keeps its null. The Vue cases, the package stand-ins (fake-store) and the enums merged with a namespace aren't run there: they are type-checked (tsc, vue-tsc) and compared with the expected output.