0
Is this possible with TypeScript?
Hi all, I was wondering if there is any way to write some code using typescript that has the same functionality as the code below. I am especially interested to find out how I could pass the app and router functions to another file without creating a new instance or explicitly importing it. Is this only possible in JS? I've tried to research it, but I can't figure out how to look it up at all. module.exports = (app)=>{ const router = require('express').Router(); require('./user')(router); require('./pet')(router); require('./ad')(router); require('./admin')(router); require('./survey')(router); app.use(router) } PS: app was declared in a different file as const app = express();
4 odpowiedzi
0
By definition, it's still compiling to javascript, that means all javascript functionality is available in typescript, since typescript is nothing but a superset of javascript.
If your question simply is it possible?
My answer: it's.
0
You're right, Technically I could just put that code in there and the Javascript files will work just fine, but I would have to ignore the compilation errors I get when I have tried that same code in a typescrypt file, so that's why I was wondering. I should have phrased the question as: is there a more typescrypt way of translating that code so that typescrypt doesn't get angry at me during compilation hehe?
0
Haha, Well if it's about typescript doesn't get angry and you don't like it to be angry, then you don't have to use it in the first place.
But since you are using it, you have to make it happy, make export default (in your case)
And make types for each parameter, In that way it will not complain.
0
And don't forget to install @types/express I think it's or tou will find it under the name of @types/expressjs.