fix(typings): correct Client method emit; type the full API; infer implement args from define schemas#2
Open
Loner1536 wants to merge 2 commits into
Open
Conversation
…mplement args from define schemas
Fixes:
- Client members are colon-methods in Luau (Controller:show, etc.) but were
typed as arrow properties, so roblox-ts emitted client.show() dot calls
with no self. Client is now declared with method signatures, and the
top-level Api (dot-functions in Luau) no longer extends it.
- commands.aliases config is a { [string]: string } map, was typed string[].
Additions (types only, no runtime changes):
- Konsole.define captures the args schema and returns a Command whose
.server is a branded string; passing it to Konsole.implement types the
callback parameters automatically (no casts or annotations needed).
Plain-string implement(name, cb) still works via overload.
- required: false args with no default type as | undefined, matching
Arguments.parse, which skips them; defaults are inserted unconverted.
- Typed Result (ok/err/table/status/from -> RenderResult), Ranks, Dispatch,
Kommand, Arguments (incl. the converter registry), Chat, Render, and the
full Config groups so create()/config overrides autocomplete.
- rank fields accept built-in rank names (player/helper/moderator/admin/
creator + aliases) alongside numbers.
- define's type parameter defaults to its constraint instead of [] so
editors show Argument property completions inside partially-typed args
(an empty-tuple default left completions with a never contextual type).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Member
|
after reviewing, please fix the |
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.
Types-only PR — no
.luauchanges and no runtime behavior changes. Rewritestypings/index.d.tsto match the Luau source and adds schema→callback inference for roblox-ts consumers.Fix
Clientmethods emitted as dot calls.Controller's members are colon-methods (function Controller:show()), but the typings declared them as arrow properties, so roblox-ts emittedclient.show()— noself— and every method on aKonsole.create()client failed at runtime from TS.Clientnow uses method signatures, and the top-levelApino longer extends it, since the top-level functions are dot-style ininit.luauand must keep emittingKonsole.show().Additions (all backward compatible)
Schema→callback inference.
definecaptures theargsschema and returns aCommandwhose.serveris a branded string (ServerName<A>; plain string at runtime). Passing it toimplementtypes the callback parameters automatically:implement("name", cb)with a plain string still works via overload.Optional-arg truthfulness.
required: falsewith nodefaulttypes as| undefined, matchingArguments.parse(which skips such args); args with adefaultstay non-optional (defaults are inserted unconverted), and an absentrequiredbehaves as required.Full API surface typed from source:
Result(ok/err/table/status/from→RenderResultperresult.luau),Ranks(incl.RankEntity = Player | userIdand the built-in rank-name union),Dispatch,Kommand,Arguments(incl. theArguments.typesconverter registry),Chat,Render, and everyConfiggroup socreate()overrides autocomplete.Editor completions inside
args.define's type parameter now defaults to its constraint instead of[]— the empty-tuple default gave partially-typed arg objects anevercontextual type, so editors showed no property completions.Verification
src/(dispatch,kommand,arguments,ranks,config,result,controller).consttype parameters require TS ≥ 5.0 (roblox-ts already requires newer).Notes
host's implementations record usesRun<Array<any>>—unknown[]would reject typed callbacks under contravariance.ExecuteResultisOutcome | RenderResult; commands returning arbitrary tables still pass through at runtime.Render.Formatter/Render.Textare leftunknown(UI internals).Disclosure
The main thing I wanted fixed was auto-typing for
implement— in the upstream typings,definereturns a plainCommandwith no arg capture,implementtakes(name: string, callback: Run)whereRunis(context, ...unknown[]), and all the sub-modules (Ranks,Dispatch,Context.dispatch, etc.) are typedunknown. So there was no inference at all: you'd define a command with a typedargsschema and still have to manually annotate every callback parameter.The upstream
Clientinterface also has every member as an arrow property (dot-call style), but the Luau controller uses colon-methods, so allKonsole.create()client calls were emittingclient.show()with noselfand failing at runtime.I didn't have time to audit the full typings rewrite myself, so I ran it through Claude (Fable 5), which traced each declaration against the Luau source module-by-module. I've reviewed the result and it's been tested in-game, but a second pair of eyes on the API surface wouldn't hurt.
🤖 Generated with Claude Code