fix(typegen): type TRANSFORM_MAP callbacks against actual method types#33
Merged
Conversation
The generator emits per-method transform callbacks like `(v) => v.map((i) => i)` inside TRANSFORM_MAP. Without parameter annotation those v / i / response identifiers trip noImplicitAny in strict-mode consumers. Keep the outer parameter unknown -- preserves contravariant assignability to the runtime's TransformFn = (value: unknown) => unknown -- and narrow once via `const t = v as <method-type>` inside the callback body. The runtime expression already references `t`, so the typed binding satisfies strict-mode without adding casts at the consumer side or weakening the runtime contract. Method input types are rendered from the same DataType the generator already has (Deserialize-phase for args, Serialize-phase for event args and results -- matching what the IPC bridge actually passes through the callback). Channel handlers get the same treatment with the inner `response` parameter typed against the channel's payload DataType.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The TRANSFORM_MAP generator emits per-method transform callbacks like
(v) => v.map((i) => i). Without parameter annotation, thosev/i/responseidentifiers tripnoImplicitAnyin strict-mode consumers, and consumers have no clean place to silence it (the whole file is auto-generated).Approach
Keep the outer parameter
unknownso the callback remains contravariantly assignable to the runtime'sTransformFn = (value: unknown) => unknown. Narrow once inside the body viaconst t = v as <method-type>. The runtime expression already references that bound identifier, so the typed binding satisfies strict mode without weakening the runtime contract.Before:
After:
The type for
tis rendered from the sameDataTypethe generator already had on hand (Deserialize-phase for args, Serialize-phase for event args and results -- matching what the IPC bridge actually passes through the callback). Channel handlers get the same treatment with the innerresponseparameter typed against the channel's payloadDataType.Test plan
cargo build -p taurpccleanTS7006: Parameter 'v' implicitly has an 'any' typeerrors clear without any consumer-side@ts-ignoreor tsconfig escape hatchesNotes
The runtime types (
TransformFn,MethodTransform,TransformMapinsrc/index.ts) intentionally stay at(value: unknown) => unknown-- generators and hand-written consumers should both be allowed to widen to that shape.