Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for type declarations and Intersection types #1330

Open
markwpearce opened this issue Oct 18, 2024 · 2 comments
Open

Support for type declarations and Intersection types #1330

markwpearce opened this issue Oct 18, 2024 · 2 comments
Labels
BrighterScript enhancement New feature or request
Milestone

Comments

@markwpearce
Copy link
Collaborator

markwpearce commented Oct 18, 2024

It would be nice be able to support "mixins" to interfaces...

Basically, some way of being able to say this interface is composed of these other interfaces:

Eg. source/mixins/alpha.bs:

interface AlphaM
   alpha as boolean
end interface

sub initAlpha()
   m.alpha = true
end sub

components/MyComponent.xml

<component name="MyComponent" extends="Group">
    <script type="text/brightscript" uri="pkg:/source/mixins/alpha.bs" />
    <interface>
       <field id="text" type="string" />
    </interface>
</component>

components/MyComponent.bs

typecast m as MyComponentM

interface MyComponentM
   top as roSGNodeMyComponent
   include AlphaM ' not married to this syntax, but this is the magic
end interface

sub init()
   initAlpha()
  print m.alpha ' this is known to be a boolean
end sub
@markwpearce markwpearce added BrighterScript enhancement New feature or request labels Oct 18, 2024
@markwpearce markwpearce added this to the v1.1.0 milestone Oct 18, 2024
@TwitchBronBron
Copy link
Member

TwitchBronBron commented Oct 20, 2024

For most basic cases (including the one you just listed), this would just be interfaces extending other interfaces:

interface MyComponentM extends AlphaM
   top as roSGNodeMyComponent
end interface

However, for multiple extension, I think we should do it how typescript does, with a type statement and type unions:

type ManyComponents = MyComponentM & AlphaM & roSGNodePoster

This would be even nicer if we eventually add inline interface types, because then you wouldn't have to name them ahead of time (not sure about the syntax, but something like this?):

type ManyComponents = AlphaM & roSGNodePoster & {
    top as roSGNodeMyComponent
}

@markwpearce
Copy link
Collaborator Author

OK... Changing this topic to be "Support for type declarations and Intersection types"

@markwpearce markwpearce changed the title Support for "mixin" interfaces Support for ~"mixin" interfaces~ type declarations and Intersection types Nov 4, 2024
@markwpearce markwpearce changed the title Support for ~"mixin" interfaces~ type declarations and Intersection types Support for type declarations and Intersection types Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BrighterScript enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants