Feature: Add Typescript#34
Open
grosuigor wants to merge 1 commit into
Open
Conversation
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.
Add full TypeScript type coverage for Observable/Observer capstone
Summary
This PR migrates the capstone solution from untyped JavaScript to fully typed TypeScript, satisfying the readme acceptance criterion that the entire code sample be covered with types.
index.jstoindex.tswith strict typing onObserver,Observable, request handling, and all mock datatypes/directory with domain-specific type files and a barrel export viatypes/index.tsObserverLikeandObservableLikecontracts so both classes explicitly implement the observer pattern interfacetsconfig.jsonwithstrict: truefor compile-time safetyChanges
Core implementation (
index.ts)ObserverimplementsObserverLikewith typednext,error,complete, andunsubscribemethodsObservableimplementsObservableLikewith a typedSubscribeFnconstructor andsubscribemethoduserMock,requestsMock, and all handler functions are explicitly typedHandlerResponseType definitions (
types/)http.tsHTTP_METHOD,HTTP_STATUSuser.tsUserRole,Userrequest.tsPostRequest,GetRequest,Request,RequestError,HandlerResponsehandlers.tsNextHandler,ErrorHandler,CompleteHandler,Handlerssubscription.tsUnsubscribe,Subscriptionobserver.tsObserverLikeobservable.tsSubscribeFn,ObservableLike,ObservableFactoryindex.tsNotable typing decisions
PostRequestrequires a typedUserbody;GetRequestrequiresparams, preventing invalid request shapes at compile timeRequestError— structured error type replacinganyUserRole— narrowed to'user' | 'admin'instead of genericstring[]_unsubscribe— satisfiesstrictPropertyInitializationwithout weakening type safetyTooling
tsconfig.jsonwith strict mode enabledindex.jsin favor of the typed implementationTest plan
npx tsc --noEmit— compiles with zero errors under strict modeindex.tsandtypes/ObserverandObservablesatisfy their*LikeinterfacesrequestsMocktype-checks asRequest[](POST withUserbody, GET withparams)HandlerResponsewith validHTTP_STATUSvaluesnode index.ts(or equivalent) and verifycomplete/unsubscribedlog outputAcceptance criteria
ObserverandObservableare fully typedany)