You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to extend (overload) restify typing. In fact, I want a propery $authenticatedUser to be globally available in all requests.
I've made this typings, which looks to work in VsCode:
// in types/restify/index.d.tsdeclare module 'restify'{interfaceRequest{/** * @description The authenticated user, only available if the user has been authenticated before */$authenticatedUser?: UserInfo// UserInfo is a custom type}}
And I have a piece of code that fails to compile with ts-node:
// in auth.middleware.tsreq.$authenticatedUser=decodedToken;
It says "property $authenticatedUser is not found in type Request."
The weird thing is that: tsc --noEmit works fine.
PS: I've tried to add ./src/types/ to typeRoot in compilerOptions, but it doesn't work too in ts-node.
The tsconfig.json is missing the custom types directory in the typeRoots. It's also important to put the custom directory before the builtin @types directory. Also make sure you actually augment the module by importing the Request interface from restify, otherwise it won't find the original properties of the Request.
For future reference, here's how to get the mentioned example work:
// types/restify/index.d.ts// Make sure you import from the original restify module!import{Request}from"restify";declare module 'restify'{interfaceRequest{$authenticatedUser?: {a: string};}}// src/index.tsimport{Request}from"restify";functionmain(req: Request){console.log(req.complete);console.log(req.$authenticatedUser);}main({complete: true,$authenticatedUser: {a: "foo"}}asunknownasRequest)
Closing as answered. Friendly reminder that the issue tracker is reserved for bugs and feature requests. Support requests should be asked in the TypeScript Discord or the discussion forum: https://github.com/typeStrong/ts-node/discussions
Hi,
I am trying to extend (overload) restify typing. In fact, I want a propery
$authenticatedUser
to be globally available in all requests.I've made this typings, which looks to work in VsCode:
And I have a piece of code that fails to compile with
ts-node
:It says "property
$authenticatedUser
is not found in typeRequest
."The weird thing is that:
tsc --noEmit
works fine.PS: I've tried to add
./src/types/
totypeRoot
incompilerOptions
, but it doesn't work too ints-node
.Am I missing something obvious here?
Thanks in advance!
Specifications
tsconfig.base.json:
The text was updated successfully, but these errors were encountered: