Skip to content

Support inline object types #338

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

Closed
singpolyma-shopify opened this issue Nov 19, 2018 · 3 comments
Closed

Support inline object types #338

singpolyma-shopify opened this issue Nov 19, 2018 · 3 comments

Comments

@singpolyma-shopify
Copy link
Contributor

export function add(a: { x: i32 }): i32 {
    return a.x;
}
@dcodeIO
Copy link
Member

dcodeIO commented Nov 19, 2018

Should be doable, but with caveats. For example, a type { x: i32, y: i32 } would be incompatible to { y: i32, x: i32 } due to the fact that static field layout differs. Similarly, { x: i32 } would be incompatible to { y: i32, x: i32 } etc.

Question is, should it still be supported nonetheless? Currently, one has to use an explicit class to make it work, i.e.

class MyType { x: i32 }

export function add(a: MyType): i32 {
    return a.x;
}

which feels a bit more natural given the limitations.

@trusktr
Copy link
Member

trusktr commented Dec 11, 2018

I think it can work, the ordering issues can be abstracted away. If the overall shape of objects is known, regardless of order, then could the compiler just ensure the same order in the output? Or can the compiler just pass the dereferenced values individually to the function parameters ?

@dcodeIO
Copy link
Member

dcodeIO commented May 27, 2020

Closing this issue as part of 2020 vacuum as it appears to be outdated and superseded by efforts to use a class type instead, and create instances from object literals. The new approach has several advantages in that no virtual lookups are involved.

@dcodeIO dcodeIO closed this as completed May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants