Skip to content

Conversation

@markwpearce
Copy link
Collaborator

Previously, everything returned from createObject was ObjectType

Now, it looks at the arguments, and if passed string literals, it is able to infer either the built-in Component/Object or a custom component:

dateTime = createObject("roDatetime") ' this is the InterfaceType `roDateTime`
dateTime.getHours() ' this is an integer


button = createObject("roSgnode", "Poster") '  this is the ComponentType `roSgNodePoster`
button.uri ' this is a string

if the args are not string literals, it still just returns ObjectType....

function getObject(objectName as string)
    return createObject(objectName) ' this is just ObjectType
end function

@markwpearce markwpearce added this to the v1.0.0 milestone May 3, 2024
Copy link
Member

@TwitchBronBron TwitchBronBron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not crazy about using a callback function on the TypedFunctionType class. Makes it harder to evaluate/inspect/reason about the type. And once this signature is there, it's going to be a breaking change to remove it if we need to redesign this feature/functionality in the future.

I'd much rather see proper overloading support implemented like they do in typescript, along with string literal value types. Something like this:

function createObject("roSGNode", "Label") as roSGNodeLabel
function createObject("roSGNode", "Rectangle") as roSGNodeRectangle

These would be auto-injected into the program when we define all the built-in types, and then we'd augment that list with the user-defined objects.

@markwpearce
Copy link
Collaborator Author

Ok. Hmmm. I don’t know about making support for overloading functions yet, so maybe I’ll change this so it’s just a special case, and does not change the interface/constructors for anything yet.

@markwpearce markwpearce requested a review from TwitchBronBron May 6, 2024 12:32
Copy link
Member

@TwitchBronBron TwitchBronBron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest changes feel much better, protects us a bit from breaking changes. Thanks!

@TwitchBronBron TwitchBronBron merged commit fcd8d26 into release-1.0.0 May 6, 2024
@TwitchBronBron TwitchBronBron deleted the createObject_implies_type branch May 6, 2024 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants