Bun TypeScript 5 Decorators not working #16379
Unanswered
angelhdzdev
asked this question in
Q&A
Replies: 2 comments
-
No idea what happened. I moved to a new computer. Upgraded bun and typescript to latest. Tried same code. Now it works. |
Beta Was this translation helpful? Give feedback.
0 replies
-
ReopeningIt's so strange. Even forcing bun to read my tsconfig.json using --tsconfig flag, it's using the experimental decorators. But again, This must be a bug. Code: function classDecorator() {
return (target: any, ctx: ClassDecoratorContext) => {
console.log({target, ctx})
}
}
function methodDecorator() {
return (target: any, ctx: ClassMethodDecoratorContext) => {
console.log({target, ctx})
}
}
function fieldDecorator() {
return (target: any, ctx: ClassFieldDecoratorContext) => {
console.log({target, ctx})
}
}
@classDecorator()
class MyClass {
@fieldDecorator()
myField!: string
@methodDecorator()
myMethod() {
}
} With bun:
With tsx:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been using bun to run
src/main.ts
for months. I've been working on that file to test different ideas with typescript decorators for backend.TypeScript experimental decorators, and the new v5 decorators worked.
Today, I worked in the same file, but completely new code.
Just a class with class and method decorators.
The 2nd parameter of the class method decorator is the ClassMethodDecoratorContext in the v5 decorators.
I was console.log( ctx.name ) and it returned undefined and I was confused.
So I console.log( ctx ) and it returned "signIn", the name of the AuthController class method.
So I console.log( target ) and instead of being a function, as in the new decorators, it returns the whole class as in the old decorators!!!
I checked the tsconfig, and i dont have any option for the experimental decorators.
Then I ran
bunx tsx src/main.ts
and it works as expected, sotsx
package is respecting the tsconfig.typescript 5.7.2, bun 1.1.43.
So either bun is not reading my tsconfig.json, or it's using the experimental decorators by default if it's not explicitly defined.
What changed!?
Beta Was this translation helpful? Give feedback.
All reactions