Skip to content

Fix type for FieldRegistry #8059

@maribethb

Description

@maribethb

Check for duplicates

  • I have searched for similar issues before opening a new one.

Description

We have a currently non-exported type used internally in Field and the field registry called FieldProto. This is the type used for the parameter where you pass the actual field class into the registry. There's a few problems with it

  1. It's not exported, so if an external developer needs to explicitly type that parameter, they can't. Most people can probably rely on type inference (just pass a parameter with no explicit type) but code.org calls this function from another function where the parameter type of their function needs to match, and they have no way to get to this type
  2. It's not quite correct. The reason we're using this type instead of just Field or typeof Field or something is because some of the field subclasses change the constructor type signature, so the subclass constructor isn't compatible with the Field constructor. But because it uses Pick the type strips out any properties other than prototype from the typed object. This is fine for the cases where all we're doing is actually referencing the prototype itself anyway. But in the registry that's not what we're doing, leading to the unfortunate (fieldObject as unknown as {fromJson: fromJson}) Edit: this was kind of wrong, but now there's more/better/hopefully correct explanation in fix: improve types in FieldRegistry #8062

either the developer:

  • is using type inference and just passing a Field or subclass anyway which will continue to work with no changes (thought to be most developers)
  • is deep importing our FieldProto type which won't be supported in v11 anyway so is already a breaking change for that reason (code.org is doing this)

See the discussion here for more info: #8052

Reproduction steps

Stack trace

No response

Screenshots

No response

Browsers

No response

Metadata

Metadata

Assignees

Labels

issue: bugDescribes why the code or behaviour is wrong

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions