45 questions
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 ...
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
}
...
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": {
...
"...
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:...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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) {...
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 ...
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:
...
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 ...
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){
...