Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Types #4119

Merged
merged 18 commits into from
Mar 11, 2021
Merged

Improved Types #4119

merged 18 commits into from
Mar 11, 2021

Conversation

thesunny
Copy link
Collaborator

@thesunny thesunny commented Mar 9, 2021

Description
This enables types to work with Element and Text objects with support for type discrimination. It also adds support for extending other objects like Editor, Range, Selection and Point; however, I would consider the customizing of those types as more experimental as I think there is a better way to do this.

This version of improved types only supports one type of Editor (ie. one set of customization) but you should be able to support multiple types by creating the editor in separate packages. This hasn't been tested though.

I've also:

  • Added documentation on how to use TypeScript with Slate.
  • Updated the examples to use the new custom types

Issue
Previously, an extended TypeScript PR was merged (into a @next release) based on a proposal that I had authored; however, the implementation had some issues that made it impossible to use. This PR was built alongside an actual implementation of an editor so should be usable with a real Editor.

Fixes: #3725

Example
n/a

Context
The previous version of extended TypeScript had issues when resolving a Node because a Node was a custom extension that was made up of other custom extensions like Element and Text. Removing these nested custom extensions was the solution to this problem.

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)

IMPORTANT! yarn test does pass on my computer, but is showing errors in CI. I think this may be due to the CI using a different version of TypeScript.

@thesunny thesunny merged commit a72958e into master Mar 11, 2021
clauderic pushed a commit to slate-rte/slate that referenced this pull request May 3, 2021
* Experimental release to see if CustomTypes holds up through a publish

* Add experimental release script

* Fix lint

* v0.60.5-alpha.0

* Allow null properties in setNodes

* v0.60.6-alpha.0

* Revert null properties on Transforms.setNodes

* v0.60.7-alpha.0

* Update examples to use custom Element and Text with discriminated unions

* Add documentation for using TypeScript improvements

* Be explicit about typescript version in package.json

* Force lerna bootstrap to fix build issues on CI and fix a few type examples

* Add slate devDependencies with * back

* v0.60.7

* Switch to a non prerelease version to fix lerna not linking in root

* Add documentation for not using prerelease versions and on how to create experimental releases

* Try removing lerna bootstrap and see if it works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Custom TypeScript Types to Slate
1 participant