#are there @functions/classes in typescript? like in java or python
49 messages · Page 1 of 1 (latest)
yes
how do i make one?
have you googled it
google ignores @ in front of keywords so it just googles functions/classes
thats why i came here
according to the learn java site, the @ is supposed to mean __a__nnotation __t__ype

https://www.typescriptlang.org/docs/handbook/decorators.html check this out i guess
oh, thats actually surprisingly simple, i didnt know closure functions could be used like this
@wide fox You may want to look at https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#decorators instead of the handbook link - I think the handbook link is describing the legacy TS-specific decorator semantics, rather than the new official decorator spec that is supported as of TS 5.0
i'm using ts 4.9 so this doesnt apply to me but thanks
I would probably upgrade and switch over to the official decorators personally.
(TS doesn't do semver, 5.0 is no more a breaking change than 4.9)
what defines a major version bump for ts?
They just count up to x.9 and then the next one is (x + 1).0
4.0 followed 3.9, 5.0 followed 4.9, 6.0 will come after 5.9
!close
!*:screenshot
Rather than screenshots, please provide either code formatted as:
```ts
// code here
```
Or even better, as an example on the Typescript playground https://www.typescriptlang.org/play that is as simple as possible and reproduces the issue. This makes it easier to help you and increases the chances of getting an answer.
function route(type: "get" | "post", route: string) {
const router = this.r;
return function (
func: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {
if (type === "get") {
return router.get(route, func);
}
if (type === "post") {
return router.post(route, func);
}
};
}
@route("get", "/auth/login")
getAuthLogin(req: Request, res: Response) {
res.json({ status: "ok" });
}
what's wrong with the code?
@wide fox It works okay if you turn on the new decorator syntax:
Preview:```ts
import {Request, Response} from "express"
function route(type: "get" | "post", route: string) {
const router = this.r
return function (
func: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {
if (type === "get") {
return router.get(route, fun
...```
it's saying Error: Route.get() requires a callback function but got a [object Object]
using ts 5.0.4