You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
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)
Check for duplicates
Description
We have a currently non-exported type used internally in
Fieldand the field registry calledFieldProto. This is the type used for the parameter where you pass the actual field class into the registry. There's a few problems with itFieldortypeof Fieldor something is because some of the field subclasses change the constructor type signature, so the subclass constructor isn't compatible with theFieldconstructor. But because it usesPickthe type strips out any properties other thanprototypefrom the typed object. This is fine for the cases where all we're doing is actually referencing theprototypeitself 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 #8062either the developer:
Fieldor subclass anyway which will continue to work with no changes (thought to be most developers)FieldPrototype 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