I finished the frontend of our current site, but now that i'm trying begin creating the backend using typescript, some sore spots of the current defined types have emerged, so I wrote some fixes
Quick Rundown
The most important change
currently, globals are exported this way:
declare function ROUTE(...);
This actually doesn't work, while you can import them "fine", and even typechecks, using something like:
import { ROUTE } from "total4";
export function install() {
ROUTE("GET /");
}
Which causes an exception once you try to actually run the program:
TypeError: (0 , total4_1.ROUTE) is not a function
Simply changing the declarations to:
declare global {
....
function ROUTE(...);
...
}
Fixed this issue, and now it compiles and typechecks properly.
Other changes
SchemaOptions was missing the recently added action function, that was added, I also added a SchemaActionOptions type
SchemaOptions.before type was removed, since that function has been removed.
RouteAction only took functions with (req, res) arguments, i'm assuming due to FILE routing, this actually prevented functions for any other type of routing from being used]\, since those can take any number of arguments, expanded the type to accept (...args: any) => void; functions
Similarly, ROUTE only allowed RouteActions, I expanded the parameter type of ROUTE to also accept strings, to allow passing the name of a view
Since any means literally "any type", any | null definitions are redundant, and even show as any in type hints, those were removed just for the sake of visual clarity
SUCCESS had its own type, but it wasn't used, that was fixed
RESTBuilder.cache was incorrectly defined as cache: (string) => RESTBuilder;, this was changed to cache: (expire: string) => RESTBuilder;
This is not at all an exhaustive list of all the problems there might be, this are just the problems I ran into while trying to get this running, i'm also not a typescript pro at all, as a matter of fact this will be my first project, so I might have just been doing things wrong, I did these changes because no matter how I try, I can't get this to work without them. at least not without basically creating my on .d.ts file. I understand typescript is not really a supported use cause, just doing what I can to improve the library.
If no other change makes it, I would really appreciate if the change to the way globals are exported is made is kept.
I finished the frontend of our current site, but now that i'm trying begin creating the backend using typescript, some sore spots of the current defined types have emerged, so I wrote some fixes
Quick Rundown
The most important change
currently, globals are exported this way:
This actually doesn't work, while you can import them "fine", and even typechecks, using something like:
Typescript actually compiles the following code:
Which causes an exception once you try to actually run the program:
Simply changing the declarations to:
Fixed this issue, and now it compiles and typechecks properly.
Other changes
SchemaOptions
was missing the recently addedaction
function, that was added, I also added aSchemaActionOptions
typeSchemaOptions.before
type was removed, since that function has been removed.RouteAction
only took functions with(req, res)
arguments, i'm assuming due toFILE
routing, this actually prevented functions for any other type of routing from being used]\, since those can take any number of arguments, expanded the type to accept(...args: any) => void;
functionsROUTE
only allowedRouteAction
s, I expanded the parameter type ofROUTE
to also accept strings, to allow passing the name of a viewany
means literally "any type",any | null
definitions are redundant, and even show asany
in type hints, those were removed just for the sake of visual claritySUCCESS
had its own type, but it wasn't used, that was fixedRESTBuilder.cache
was incorrectly defined ascache: (string) => RESTBuilder;
, this was changed tocache: (expire: string) => RESTBuilder;
This is not at all an exhaustive list of all the problems there might be, this are just the problems I ran into while trying to get this running, i'm also not a typescript pro at all, as a matter of fact this will be my first project, so I might have just been doing things wrong, I did these changes because no matter how I try, I can't get this to work without them. at least not without basically creating my on
.d.ts
file. I understand typescript is not really a supported use cause, just doing what I can to improve the library.If no other change makes it, I would really appreciate if the change to the way globals are exported is made is kept.