When constructing St.Widget
, specifying layout_manager
(as a subclass of LayoutManager
) should be reflected in types
#145
Labels
gjs-convention
Marks issues for aligning with GJS coding standards and practices
From gjsify/gnome-shell#18
When one constructs a
St.Widget
like this:The type of
myWidget.layout_manager
is stillLayoutManager
, which would make TypeScript errors when one tries to use methods fromGridLayout
.Suggestion 1: Multiple type parameters
Warning
ConstructorProperties
now shouldn't be a single interface, but a union of snake_case properties and camelCase properties. Keeping it as a single interface would have required user to specify bothlayout_manager
andlayoutManager
, which would be absurd.Suggestion 2: Type dictionary as a single type parameter
Note
I strongly recommend this solution.
ConstructorProperties
does not need to change at all.The two suggestions above still have a flaw: It now requires TypeScript user to pass
null
explicitly, optional parameter is no longer allowed.If you want to fix this flaw, then I suggest stop using the
class
keyword. Instead, you should utilize the TypeScript feature that allows merging variable and type, like so (assuming you choose "suggestion 2"):As for me personally, whether I have to pass
null
explicitly makes little difference.The text was updated successfully, but these errors were encountered: