Skip to content

createTextPath only accepts VectorNode, so its own documented example does not compile #388

Open

Description

@sebxt

figma.createTextPath is typed as taking a VectorNode, but the JSDoc for the same method says the node "can be VectorNodes, shape nodes (Rectangle, Ellipse, Polygon, Star), or Line nodes", and the example in that JSDoc passes an ellipse.

What happens: the documented example fails to type check.

const circle = figma.createEllipse()
circle.resize(200, 200)
await figma.loadFontAsync({ family: "Inter", style: "Regular" })
const textPath = figma.createTextPath(circle, 2, 0.5)
error TS2345: Argument of type 'EllipseNode' is not assignable to parameter of type 'VectorNode'.

The same error appears for RectangleNode, PolygonNode, StarNode and LineNode. Plugin authors have to cast or flatten the shape first, even though the API accepts these nodes directly.

What should happen: every node type listed in the @param node description is accepted, so the example compiles without a cast.

Root cause: the declaration in plugin-api.d.ts and plugin-api-standalone.d.ts is createTextPath(node: VectorNode, startSegment: number, startPosition: number): TextPathNode. The parameter type was never widened to match the documented set of vector like nodes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions