Consider removing [key: string]: any
from interfaces, and use type generics in function definitions.
#3416
Labels
[key: string]: any
from interfaces, and use type generics in function definitions.
#3416
Do you want to request a feature or report a bug?
Feature (for TypeScript users of Slate).
Problem discussion
In the current version of Slate core (
v0.57.1
), interfaces are declared in the following way...and most Slate functions are written in a form like the following:
The problem with this is that TypeScript users would likely want to constrain their
Text
nodes in their own way, above and beyond the underlyingText
,Editor
, etc interfaces, while still allowing them to be used directly in helper functions without usingas
type coercions.For example:
The
CompanyText
type is still overly permissive because a typo likeisBeld
is still allowed, despite the user's extended interface (thanks to key-any). And the user would also have to usemyTextNode as Text
when callingText.decorations()
on it, otherwise TypeScript will complain.Proposed solution
Use type generics in functions, and remove the
[key: string]: any
from interfacesThis will allow TypeScript consumers of Slate to use it in the
CompanyText
example above.The text was updated successfully, but these errors were encountered: