问题
I've looked around at various github threads and it seems as if SVG support is not merged / shipped in current versions of Flow.js (I'm using VS Code extension vscode-flow-ide
). I'm trying to work with SVG refs and for now have had to use a mix of less-specific type (Element
) and // $FlowFixMe
to work around these - not ideal from a broader type-safety perspective.
Anyone solved this? I'm using /flow/lib/dom.js
currently, but it lacks these types.
回答1:
Interrim solution until the official inclusions are made...
For types that are missing, implement your own for that subset of properties that you intend to use.
For example, I am manipulating SVGs, so in a file SVGElement.js.flow
(named after the DOM type):
type SVGElement = HTMLElement &
{
fonts: [],
fillOpacity: number
//...
//In reality, SVGElement has many more properties, but you can include
//only those you will use and which thus require type-safety.
//You can add whatever you need, incrementally, as time passes.
}
Typing only subsets of methods & properties is easier than having to implement the entire type.
The &
allows inheritance from HTMLElement
present in /flow/lib/dom.js
; see intersection types.
来源:https://stackoverflow.com/questions/59578362/svg-types-support-in-flow-js