What does the at sign mean in the latest TypeScript presumably v1 5 example

0 votes

A very interesting image has been posted on the official TypeScript blog.

Wierd syntax

I'm curious what the @ (at sign) symbol is doing there since it can't be used in JavaScript identifiers (as far as I know).

Aug 1, 2022 in TypeSript by Elton
• 400 points
856 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 Aug 3, 2022 by Abhinaya
• 1,160 points

Related Questions In TypeSript

0 votes
1 answer

What does the @ (at sign) sign do in TypeScript?

The big news this week is the ...READ MORE

answered Jun 10, 2022 in TypeSript by Nina
• 3,060 points
1,067 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, 2022 in TypeSript by Nina
• 3,060 points
1,142 views
0 votes
1 answer

What do square brackets mean in a type definition in Typescript?

I've missed a basic type of TypeScript: Tuples. So ...READ MORE

answered Jun 22, 2022 in TypeSript by Nina
• 3,060 points
3,167 views
0 votes
0 answers

What is a type in Typescript for the Component class in Angular 2+?

I have a small problem, but big ...READ MORE

Jul 5, 2022 in TypeSript by Logan
• 2,140 points
747 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, 2022 in Others by narikkadan
• 63,600 points
2,208 views
0 votes
1 answer

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

Just add this in the app.module.ts file: import { FormsModule ...READ MORE

answered Apr 30, 2022 in Other DevOps Questions by narikkadan
• 63,600 points
4,433 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, 2022 in TypeSript by Nina
• 3,060 points
4,836 views
0 votes
1 answer

Square brackets around vs after expression in Typescript

x is an Array, while y is a Tuple. The ...READ MORE

answered Jun 7, 2022 in TypeSript by Nina
• 3,060 points
3,778 views
0 votes
1 answer

What is the question mark for in a Typescript parameter name?

It is to mark the parameter as optional. TypeScript ...READ MORE

answered Aug 3, 2022 in TypeSript by Abhinaya
• 1,160 points
1,427 views
0 votes
1 answer

The Angular Compiler requires TypeScript >=3.4.0 and <3.5.0 but 3.5.3 was found instead

Run this script to find exact version npm ...READ MORE

answered Aug 3, 2022 in TypeSript by Abhinaya
• 1,160 points
4,873 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP