Skip to main content
1 vote
0 answers
41 views

Can JS decorators add to a TypeScript interface? [duplicate]

Given function addUnderscore(...) { // adds `_${fieldname}` to class } class Foo { @addUnderscore x=1 @addUnderscore y=2 } Can I get tsc to notice that Foo._x exists because of ...
user avatar
0 votes
1 answer
37 views

Referencing class in function decorator call

I'm trying to pass a parameter to a decorator that references it's own class: export class SomeClass { public async handleError(error: Error): Promise<void> { // ... treating errors } ...
his dudeness's user avatar
1 vote
0 answers
495 views

Trouble Using Decorators in Vite Typescript SWC

I created a vite typescript swc project, and I am having trouble getting decorators to work. I added this in tsconfig.app.json: { "compilerOptions": { ... "...
Jeffery Tang's user avatar
1 vote
1 answer
478 views

Override Property Typing of Lit-Element Subclasses in TypeScript

When subclassing a lit-element Class to add further typing, should the @property decorator be overridden or just the type and initializer? In otherwords, suppose I have this code: interface AB { a:...
Michael Scott Asato Cuthbert's user avatar
0 votes
1 answer
254 views

Upgrade JS decorator to the 2023-05 proposal?

I have a decorator to inject my common stylesheets into lit components written with the legacy 2018 proposal (as what was previously supported by lit). Upgrading to lit 3, they changed to the 2023-05 ...
Joe Jankowiak's user avatar
2 votes
0 answers
124 views

Decorator can't be called

I've started learning Typescript and now I'm learning about decorators but for some reason it just won't work even with the example code from the official website. I'll share you my code, maybe you ...
Bekobiii's user avatar
0 votes
2 answers
490 views

Constructor Function Type for Class Decorators

I have a class decorator where I want to pass type for a constructor function parameter to avoid linting error,so I can't pass type as Function.For Example- function Student(config) { return ...
Robin Chugh's user avatar
1 vote
1 answer
657 views

TypeScript stage 3 fields decorators

I'm currently trying to update a field decorator from experimental TypeScript to stage 3. All it does is send a notification when the value of a field is updated. The old implementation looks like ...
Barosanu240's user avatar
0 votes
1 answer
495 views

How to output decorators in compiled TypeScript

This is an example of a class inside an index.ts file that makes use of a decorator i.e myDecorator. export class TestClass { @myDecorator() testFn() {} } When I compile this using tsc, it ...
matthew2564's user avatar
2 votes
1 answer
490 views

How to turn the class definition to Vue 3 component definition with "tc39" decorators?

The API purposed in tc39/proposal-decorators is pretty different with previous decorators API. Although the TypeScript 5 does not fully support the new API yet, the deprecating of the previous API is ...
Takeshi Tokugawa YD's user avatar
0 votes
1 answer
211 views

Improving Socket.io code with Typescript Decorators

I am trying to simplify the logic of socket.io by using decorators as follows: const Event: any = (name) => { return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {...
Andrea D'Attero's user avatar
2 votes
1 answer
1k views

NodeJS JavaScript project with JS decorators (stage 3) and Babel doesn't work

I am trying to use JavaScript decorators (stage 3 proposal) in my NodeJS project, which is written in JavaScript. However, I am having trouble getting this to work with nodemon and babel together, so ...
Anatoly's user avatar
  • 5,281
0 votes
2 answers
74 views

Function Expression vs Function Declaration in Javascript Decorators

I have a problem understanding how different ways to create a function are affecting decorators. I am trying to create a decorator that will allow me to count how may times function was called: ...
Иван Бельков's user avatar
0 votes
0 answers
36 views

Retain the list of the properties of a class

I'm creating annotations to add functionalities to some classes at runtime, like the following: const anno = function () { return function (Class, descriptor) { // can I have the list of ...
dooxe's user avatar
  • 1,490
0 votes
3 answers
2k views

Unable to access value using Property decorator in typescript

I am writing a Vanilla Typescript Program, as shown below class DecoratorClass{ @HelloWorld public property1:string="Siddu Rocks" } function HelloWorld(target:any,propertyName:string){ ...
Siddarth's user avatar

15 30 50 per page