fix(typings): correct Client method emit; type the full API; infer implement args from define schemas - #2
Conversation
|
after reviewing, please fix the |
|
Rebased onto v0.1.9 HF 1 and synced the typings with the latest config refactor (removed |
|
Pushed fixes for all four issues (989f412):
Verified all four with |
|
Wrote a full type-test suite against the typings (every module: define/implement/host/run, Client, Ranks, Dispatch, Kommand, Arguments, Chat, Result/Render, Config — with the unsound cases from your review pinned as |
|
I'll recheck this soon, please update to the latest version though |
…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>
…axHeight, hintHeight, bottomInset)
- brand Client with a nominal marker so the dot-call Api is no longer structurally assignable (prevents roblox-ts emitting colon calls against dot functions, which shifted args at runtime) - reject branded ServerNames in the loose implement overload so an annotated callback can't bypass the schema-inferred tuple; also block inference from the callback (NoInfer) so the branded name alone determines the arg types - RunArgs falls back to ReadonlyArray<any> for widened Argument[] schemas instead of [] (run callbacks with args compile again) - restore panel.hintHeight (runtime still defines and uses it)
Konsole.implement delegates to Dispatch.implement at runtime, but the Dispatch module's typing still accepted a branded ServerName with any callback annotation. Both now share one Implement overload pair.
acf97ca to
c633312
Compare
|
Rebased onto v0.1.10. Merged in the new |
…ever-hole on player/players Konsole never mutates these after handing them back out - Command.args/aliases, Rank.aliases, KommandModule.schemas(), and the default config's input.activationKeys/commands.aliases are all live references into internal tables, so exposing them as mutable arrays let consumers silently corrupt shared state. Also caught the same "suggestions on player/players" gap Finchasaurus flagged on the Argument union in KYRORBLX#5 - those variants never read .suggestions, so it should be excluded there too, not just on string/number/boolean.
|
Went back through every .luau file to double-check the typings against actual runtime behavior, since #5 caught a real gap (suggestions readonly). Found the same pattern in a few more places — pushed a follow-up:
Sanity-checked with a small tsc pass ( |
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