You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there... I am struggling trying to find documentation on the TypeScript metadata annotation features that are apparently coming in 1.5... my question is how will interfaces work with metadata annotations knowing that TS interfaces have no runtime form???? take the following TS code:
class Server{
}
class Client{
constructor(svr: Server){
}
}
I have not been able to find much detail on how TS will handle this, but based on the old AtScript documentation, I believe the transpiled JS code will look something like this:
function Server(){
}
function Client(svr){
}
Client.parameters = [{is: Server}];
That's all fine and good but what will the JS look like if the TS is like that below whereby we introduce an interface??????
As for type serialization, interfaces will actually not carry any metadata (they will just represented as the Object constructor function); however, classes will be serialized. You can see the specifics for our the scheme here. Keep note that this is a work in progress and we're ironing out the details.
it all looks great EXCEPT the interfaces... don't you think it's a serious problem that there's no way to query metadata for interfaces? In my case for example I would never ever do the first example I gave above. Instead I would always do the second which is program against an interface, and I would dare say this is usually the norm rather than the exception among devs. At the very least you guys could write out the fully qualified name of the interface. I never really understood why you guys don't produce a JS function for TS interface declarations.
One other question I have... is TS going to always automatically generate basic metadata about TS classes OR do we always have to create and use decorators for this? For example, I believe AtScript was going to always generate metadata about the constructor function's parameter types without the developer having to do anything (see "Metadata Annotations" section of https://docs.google.com/document/d/11YUzC-1d0V1-Q3V0fQ7KSit97HnZoKVygDxpWzEYW0U/mobilebasic?viewopt=127). Is TS going to do the same? I hope so....
// https://smellegantcode.wordpress.com/2015/04/02/typescript-1-5-get-the-decorators-in/
class C {
@log
foo(n: number) {
return n * 2;
}
}
function log(target: Function, key: string, value: any) {
return {
value: (...args: any[]) => {
var a = args.map(a => JSON.stringify(a)).join();
var result = value.value.apply(this, args);
var r = JSON.stringify(result);
console.log(`Call: ${key}(${a}) => ${r}`);
return result;
}
};
}
var c = new C();
console.log(c.foo(23));
Maybe this should be renamed as asking for documentation for annotations?
I tried to find annotations from handbook, there is no mention of "@", "decorator" or "annotations". Also noticed the language spec is TS 1.4 so it wasn't helpful either.
Activity
DanielRosenwasser commentedon Mar 11, 2015
See #2249 and the proposal for decorators in ES7.
As for type serialization, interfaces will actually not carry any metadata (they will just represented as the
Objectconstructor function); however, classes will be serialized. You can see the specifics for our the scheme here. Keep note that this is a work in progress and we're ironing out the details.giancarloa commentedon Mar 12, 2015
Thanks Daniel Rosenwasser (@DanielRosenwasser) for the info!!! I think I understand a little better now what's happening...
it all looks great EXCEPT the interfaces... don't you think it's a serious problem that there's no way to query metadata for interfaces? In my case for example I would never ever do the first example I gave above. Instead I would always do the second which is program against an interface, and I would dare say this is usually the norm rather than the exception among devs. At the very least you guys could write out the fully qualified name of the interface. I never really understood why you guys don't produce a JS function for TS interface declarations.
One other question I have... is TS going to always automatically generate basic metadata about TS classes OR do we always have to create and use decorators for this? For example, I believe AtScript was going to always generate metadata about the constructor function's parameter types without the developer having to do anything (see "Metadata Annotations" section of https://docs.google.com/document/d/11YUzC-1d0V1-Q3V0fQ7KSit97HnZoKVygDxpWzEYW0U/mobilebasic?viewopt=127). Is TS going to do the same? I hope so....
Thanks again
giancarloa commentedon Mar 16, 2015
since i got no response i guess it's best to close this item and ask my follow up questions in a new item.
bparadie commentedon May 7, 2015
giancarloa I found this article very helpful: https://smellegantcode.wordpress.com/2015/04/02/typescript-1-5-get-the-decorators-in/
Here is the example in Playground:
Ciantic commentedon Jun 2, 2015
Maybe this should be renamed as asking for documentation for annotations?
I tried to find annotations from handbook, there is no mention of "@", "decorator" or "annotations". Also noticed the language spec is TS 1.4 so it wasn't helpful either.
DanielRosenwasser commentedon Jun 2, 2015
Jari Pennanen (@Ciantic) I agree that we need to improve our documentation - the handbook is fairly outdated. We're currently fixing it up, and decorators are one of the new topics we intend to write about.