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 inline types #1375

Open
TwitchBronBron opened this issue Dec 16, 2024 · 1 comment
Open

Support inline types #1375

TwitchBronBron opened this issue Dec 16, 2024 · 1 comment
Labels
New Language Feature A proposal for a new feature to be added to the BrighterScript language
Milestone

Comments

@TwitchBronBron
Copy link
Member

Add the ability to define a type without giving it a name. For example, some AA structure on a class property or as a function parameter.

There are many different syntax options here.

function test(param1 as interface 
		thing as string, 
		age as string 
	end interface) as interface 
		name as string 
	end interface
		print "hello world"
		return invalid
	end function
	

	function test(param1 as interface 
		thing as string, 
		age as string 
	end interface) as interface 
		name as string 
	end interface
		print "hello world"
	end function
	
	function test(param1 as interface thing as string, age as string end interface): interface name as string
		print "hello world"
	end function

	function test(param1 as < thing as string, age as string >) as < name as string >
		print "hello world"
	end function

	function test(param1 as < thing as string, age as string >) as < 
		name as string 
	>
		print "hello world"
	end function


	function test(param1 as < thing as string, age as string >) as {
		name as string 
	}
		print "hello world"
	end function

	function test(param1 as { thing as string, age as string }) as { name as string }
		print "hello world"
	end function
	

	function test(param1 as {
		thing as string or integer, 
		age as string or {a as string}
	}) as dynamic
		print "hello world"
	end function
	

	function test(param1 as { 
		thing: string, 
		age: string
	}): {
		name: string
	} begin 
		print "hello world"
	end function

	function test(param1 as { 
		thing: string, 
		age: string
	}): {
		name: string
	} {
		print "hello world"
	}

	function test(param1 as { 
		thing as string, 
		age as string
	}) as {
		name as string
	} {
		print "hello world"
	}

	function test(param1 as { 
		thing as string, 
		age as string
	}) as {
		name as string
	}
		'function body
	end function

	' Sanitize the card footer papi components into something we can use
	function prepareCardFooter() as { subtype as string, optional title as string, optional subtitle as string	}
	function prepareCardFooter() as type(subtype as string, optional title as string, optional subtitle as string)
	function prepareCardFooter() as type subtype as string, optional title as string, optional subtitle as string end type 
	function prepareCardFooter() as type 
		subtype as string
		optional title as string
		optional subtitle as string
	end type 
		papiObject = {
			subtype: "Node"
		}
@TwitchBronBron TwitchBronBron added this to the v1.1.0 milestone Dec 16, 2024
@TwitchBronBron TwitchBronBron added the New Language Feature A proposal for a new feature to be added to the BrighterScript language label Dec 16, 2024
@markwpearce
Copy link
Collaborator

I think I like this format the best:

sub foo(input as {name: string, count: integer})

Just because it’s the most concise….

I could be swayed to have this one, but it’s a sea of as’s

sub foo(input as {name as string, count as integer})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Language Feature A proposal for a new feature to be added to the BrighterScript language
Projects
None yet
Development

No branches or pull requests

2 participants