Skip to content

[p5.js 2.0 Bug Report] (TypeScript): @chainable methods can't have overrides with different return types #8356

@LuLaValva

Description

@LuLaValva

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.1.2

Web browser and version

No response

Operating system

No response

Steps to reproduce this

Element.size() return value is incorrect

The generated types from the element size method look like this:

  size(): Element;
  size(w?: number | typeof p5.AUTO, h?: number | typeof p5.AUTO): Element;

but really they should be

  size(): { width: number; height: number }; // (or `Object`)
  size(w?: number | typeof p5.AUTO, h?: number | typeof p5.AUTO): Element;

@chainable code

I haven't narrowed down the exact problem, but when @return {Element} is used directly instead of @chainable the type compilation is more correct.

The problem source is likely this line, wherechainable is applied per-method instead of per-overload.

Proposed solutions

Quick fix: Use @return {Element} instead of @chainable when there's an override

Right fix: Figure out how to get @chainable working per-overload instead of per-method

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions