feat(types): ship TypeScript definitions for the public API - #512
Merged
Merged
Conversation
Hand-written types for FormeoEditor and FormeoRenderer, every option, event, before hook, action and DOM event, and the formData shape. npm run test:types compiles a usage fixture against them with tsc --noEmit. Refs #184
A controls.elements entry with controlSet (no tag of its own) and componentType 'controlSet'
with data { layout, row, fields } in the onBeforeAdd detail.
Refs #227
Copy src/types/formeo.d.ts to dist/formeo.d.ts and dist/formeo.d.cts after build:lib and point types plus every exports condition at them. dist.test.mjs now reads nested exports conditions and checks that tsc resolves the types from bundler and nodenext (ESM and CJS) consumers. Refs #184
Add docs/typescript.md, rewrite the README TypeScript section, and correct click.btn/save.form, the onSave example and the optional editor options argument. Refs #184
… and a field's addChild Refs #184
… TypeScript versions Refs #184
Collaborator
Author
|
🎉 This PR is included in version 5.13.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
What
Formeo now ships TypeScript definitions, so the README's "Full type definitions included" is true.
src/types/formeo.d.tsis the single, hand-written source. It coversFormeoEditorandFormeoRenderer, every option, event callback, before hook (onBeforeAdd/Remove/Clone/Save, withonBeforeAdd's detail a union keyed oncomponentType), action (click.btn,save.form,remove.component,remove.page, item removals withisClearAll), theformeo*DOM events (ondocumentand on elements),destroy(), pages and renderer pagination, control sets (controlSetdefinitions andcomponentType: 'controlSet'), and the formData shape. The old README namesFormeoOptionsandFormDatastill work, marked@deprecated.controls.disable.formActions: falseis a type error because it throws; a component'sconfig.events.onRender/onAddChildhandler is typed for both calls the runtime makes (the event, then the legacy element /{ parent, child }call); and the editor'sonRender,formeoOnRenderandformeoConditionUpdatedare left out because nothing fires them.tsc:npm run test:typescompiles fixtures (src/types/*.test-d.ts) against the d.ts, with@ts-expect-errorlines that fail if a type is loosened. It runs in CI (pull-request.yml) and on pre-push.build:lib,tools/build-types.mjscopies the d.ts todist/formeo.d.tsanddist/formeo.d.cts;package.jsonhastypesand atypescondition first in eachexports["."]entry.tools/dist.test.mjsnow handles nested conditions and checks thattscfinds the types frombundlerandnodenext(.mtsand.cts) consumers.typescript@^7.0.2, devDependency) via thetscCLI only. Commit-message linting still works with it installed (its config is inpackage.json).Docs
docs/typescript.md(what's typed, before-hook narrowing, DOM events, control sets, supported TypeScript versions: 4.7+, 5.0+ forbundler,domlib;node10needs TS ≤ 6 orbundler/nodenext; replacing your owndeclare module 'formeo'orWindowdeclarations), a rewritten README TypeScript section,docs/README.md, the editor constructor row (options are optional), the action names indocs/options/actions/README.md(click.btn,save.form), and CLAUDE.md. A separate commit fixesdocs/options/events/README.md: the edit panel events fire for stages too (Refs #316).For consumers
Code that was
anyis now type-checked, so upgrading may surface type errors in existing TypeScript code. Projects with their owndeclare module 'formeo'orWindow.FormeoEditordeclarations should delete them (formeo-io has one).Testing
npm test: 704 pass (701 on feat(controls): control sets, a control that adds a row of fields at once #511). New:src/lib/js/package-types.test.mjsnpm run test:types: cleannpm run lint: cleannpm run build+npm run test:dist: 7 passtest.skips)@arethetypeswrong/cligreen for node16 (ESM and CJS) and bundlerFollow-ups
controls.disable.formActions: falsethrows at runtime (typed as an error for now)onRender,formeoOnRenderandformeoConditionUpdatedare documented but never fired: wire them up or drop them from the docs@arethetypeswrong/cliin CIFormeoOptions/FormDataaliases in the next majorRefs #184