What does the at sign sign do in TypeScript

0 votes

A very interesting picture was posted in the official TypeScript blog.

Wierd syntax

I wonder what the @ (at sign) symbol is doing there since (as far as I know) it cannot be used in JavaScript identifiers.

Jun 9 in TypeSript by Logan
• 2,140 points
20 views

1 answer to this question.

0 votes

The big news this week is the merging of AtScript and TypeScript.

The following example from the AtScript documentation...

@Component()
class MyApp {
  server:Server;
  @Bind('name') name:string;
  @Event('foo') fooFn:Function;
  @Inject()
  constructor(@parent server:Server) {}
  greet():string {}
}

Compiles into the following JavaScript...

function MyApp() {}
MyApp.properties = {
  'server': { is: Server },
  'name': { is:string,
            annotate: [new Bind('name']},
  'fooFn': { is:Function,
             annotate:[new Event('foo')]}
}
MyApp.annotate = [
  new Component(),
  new Inject()
];
MyApp.parameters = [
  {is:Server, annotate:[parent]}
];
MyApp.prototype.greet = function() {}
MyApp.prototype.greet.returns = string;

AtScript was planned to be a layer on top of TypeScript (i.e. a super-set of a super-set) - but now the two projects are one.

Annotations are described thus:

  • AtScript annotation syntax is just a shorthand of placing the same information in ES5. It would be reasonable for an ES5 developer to write these annotations manually. A helper library could even be provided.
  • Annotations can only be placed on functions.

  • An annotation placed on a class is an annotation placed on the class’ constructor function.

  • An annotation placed on a field gets moved to the constructor function.

  • All annotations are translated as properties on a function.

answered Jun 10 by Nina
• 3,020 points

Related Questions In TypeSript

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

What does <T> do in TypeSript?

This is a TS Generics declaration. T will be declared ...READ MORE

answered May 31 in TypeSript by Nina
• 3,020 points
14 views
0 votes
1 answer
0 votes
0 answers

Function definition syntax confuse in Typescript

I figure that out: One post in ...READ MORE

Jul 5 in TypeSript by Nina
• 3,020 points
14 views
0 votes
1 answer

How to set meta tags using Angular universal SSR and ngx-seo plug-in?

first Install the plug-in with npm i ngx-seo ...READ MORE

answered Feb 11 in Others by narikkadan
• 11,280 points
688 views
0 votes
0 answers

Can't bind to 'ngModel' since it isn't a known property of 'input'

I have this  input in my component ...READ MORE

Apr 29 in Other DevOps Questions by Kichu
• 19,040 points
140 views
0 votes
1 answer

VS Code enforces semicolons, but why doesn't Angular and TypeScript not use it consistently?

JavaScript has a syntactic feature known as semicolon ...READ MORE

answered May 31 in TypeSript by Nina
• 3,020 points
44 views
0 votes
1 answer

What does the ! (exclamation mark) do in TypeScript?

The exclamation mark is called the non-null ...READ MORE

answered Jun 1 in TypeSript by Nina
• 3,020 points
119 views
0 votes
1 answer

Now I know what 'pick' does. But I want to do the opposite and remove values from an object.

You can use the keyword Omit for ...READ MORE

answered May 27 in TypeSript by Nina
• 3,020 points
18 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP