fix: network type was silently any instead of strict - #1608
Open
gomesalexandre wants to merge 1 commit into
Open
fix: network type was silently any instead of strict#1608gomesalexandre wants to merge 1 commit into
gomesalexandre wants to merge 1 commit into
Conversation
`EmptyNetwork` was declared as `ValidNetwork<string, never>`, but `ValidNetwork` is not generic. Because `network.d.ts` is covered by `skipLibCheck`, TypeScript never flagged the invalid instantiation and silently resolved `EmptyNetwork` to `any`. That poisoned the whole type: `Network = EmptyNetwork & ValidNetwork` collapsed to `any`, so every consumer of `Network` lost all type-safety on network objects. Declare `EmptyNetwork` as `Partial<ValidNetwork>` so the intersection resolves to a strict `ValidNetwork` and `Network` is a real type again. closes scroll-tech#964
|
@gomesalexandre is attempting to deploy a commit to the Scroll Team on Vercel. A member of the Team first needs to authorize it. |
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.
closes #964
what
Network(the type used across the app for network objects) was silentlyany, so every consumer lost type-safety on its fields - typos and wrong shapes compiled clean.why
EmptyNetworkwas declared asValidNetwork<string, never>, butValidNetworkis not generic. Becausesrc/types/network.d.tsis covered byskipLibCheck, TypeScript never flagged the invalid instantiation and silently resolvedEmptyNetworktoany. That collapsed the intersectionNetwork = EmptyNetwork & ValidNetworktoany.how
Declare
EmptyNetworkasPartial<ValidNetwork>so the intersection resolves to a strictValidNetworkandNetworkis a real type again.EmptyNetworkis only ever used inside theNetworkintersection, so the blast radius is limited to that.verification
Ran the repo typechecker (
tsc --noEmit) before/after:const n: Network = 123compiles (Network isany)const n: Network = 123errorsTS2322(numbernot assignable toValidNetwork) - Network is strict againTS2307: Cannot find module '@/assets/...'errors are unrelated - they come from running baretscwithout Next's webpack asset resolution, and are present identically before and after this change.