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

TypeScript compatibility #305

Closed
alveko opened this issue Oct 24, 2018 · 6 comments
Closed

TypeScript compatibility #305

alveko opened this issue Oct 24, 2018 · 6 comments

Comments

@alveko
Copy link

alveko commented Oct 24, 2018

What's currently supported and what's not in terms of the TypeScript spec, see [1]?
It's understood that the dynamic features are not there. What about the rest?

Based on other issues, nested object initialization is not currently supported.
I also get issues with interface, see [2].

[1] https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md
[2] a simple ts file

export interface xevent {
    x: i32;
}

export function foo(e: xevent): xevent {
    return e;
}

leads to

ERROR TS2304: Cannot find name 'xevent'.

 export function handle(e: xevent): xevent {
                           ~~~~~~
 in dummy.ts(5,26)

ERROR: Compile error
    at Error (native)
    at Object.main (/wp/assemblyscript/cli/asc.js:472:21)
    at Object.<anonymous> (/wp/assemblyscript/bin/asc:3:60)
    at Module._compile (module.js:577:32)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.runMain (module.js:611:10)
    at run (bootstrap_node.js:394:7)
@MaxGraey
Copy link
Member

MaxGraey commented Oct 24, 2018

Casting interface to object not support yet. Currently you can use class instead interface for that stuff.

export class xevent {
  x: i32;
}

export function foo(e: xevent): xevent {
  return e;
}

export function foo2(e: xevent): xevent {
  return { x: 1 } as xevent;
}

@alveko
Copy link
Author

alveko commented Oct 24, 2018

Where/when does the casting happen in this example?

@dcodeIO
Copy link
Member

dcodeIO commented Oct 24, 2018

Regarding interfaces: While we have a custom GC now, it's not yet fully functional and lacks some properties that'd be necessary to properly support interfaces, like virtual lookup tables and runtime class ids on instances. While this can be done, I'd favor implementing higher level features on top of the proposed higher level specs once these land (no ETA on the GC spec yet), just because improving the custom GC is a lot of work and it's likely that it'll be thrown away again later anyway.

@MaxGraey
Copy link
Member

MaxGraey commented Oct 24, 2018

Yes, for interfaces like that:

interface IFoo {
    boo(): i32;
}

with methods this required vtable. But for interfaces which just declare objects without methods like

interface IFoo {
   x: i32;
   s: string;
   f: f64;
}

Implementation could be much trivial.

@sqykly
Copy link

sqykly commented Oct 29, 2018

Does this affect abstract classes and overrides as well? That's a pretty severe limitation. Surely the C++ and Java implementations have this worked out; is there a reason this is harder with TypeScript than those other languages, or should I stroll over to their source code and bring back a working example to model yours after?

@stale
Copy link

stale bot commented Feb 8, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 8, 2019
@stale stale bot closed this as completed Feb 15, 2019
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