Skip to content

TypeScript guidelines: Add Derive types from authoritative sources guideline#178

Open
MajorLift wants to merge 2 commits into
mainfrom
jongsun/typescript/derive-from-authoritative-types
Open

TypeScript guidelines: Add Derive types from authoritative sources guideline#178
MajorLift wants to merge 2 commits into
mainfrom
jongsun/typescript/derive-from-authoritative-types

Conversation

@MajorLift

@MajorLift MajorLift commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Adds a Derive types from authoritative sources instead of re-declaring them subsection to the Type Inference section.

The section already covers preferring inference for values and avoiding accidental widening, but not the common case (especially with AI) of hand-writing a type that restates one an authoritative source already defines.

Includes counterexamples.


Note

Low Risk
Documentation-only change to docs/typescript.md; no runtime or build behavior is affected.

Overview
Adds a Type Inference subsection, Derive types from authoritative sources instead of re-declaring them, to docs/typescript.md.

It tells contributors to derive types from existing sources (controller state, returns, @metamask/* exports, schemas) via State['field'], typeof, ReturnType/Parameters, and Pick/Omit/Partial, instead of hand-written duplicates that widen shapes and drift from the source. It links to the existing widening and inference guidelines and includes a permalinked counterexample: getMetaMaskState: () => Record<string, unknown> versus composing from TokenListState to avoid per-use-site casts and as never.

Reviewed by Cursor Bugbot for commit ee26d36. Bugbot is set up for automated code reviews on this repo. Configure here.

@MajorLift MajorLift changed the title Add Derive types from authoritative sources guideline TypeScript guidelines: Add Derive types from authoritative sources guideline Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant