Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
¿Hay alguna forma de devolver instancias expresas en las clases de TypeScript?

Estoy tratando de crear el servidor express para mi proyecto en un módulo externo. Todo funciona bien hasta que intento hacer algo con el objeto de la app en mi archivo principal.

servidor.ts:

 import express from "express"; import OutputLevel from "../types/OutputLevels"; class Server { /** * Creates an express web server * @param {Number} port The port the server is listening on * @param {OutputLevel} [outputLevel] The level of console output (commonly based on CLI arguments) {@link OutputLevel} * @returns {Express} */ constructor(port: Number, outputLevel?: OutputLevel) { const app = express(); app.listen(port, () => { if (outputLevel && outputLevel >= 2) console.log(`[Server @ ${port}] Listening @ http://localhost:${port}`); }); return app; } } export default Server;

índice.ts:

 import Server from "./server/server"; import OutputLevel from "./types/OutputLevels"; let app = new Server(2020, OutputLevel.INFO); app.get("/", (req, res) => { res.send("hello world") });

Intellisense marca la parte de get como un error con la nota Property 'get' does not exist on type 'Server'. . Tal vez esto tenga algo que ver conmigo usando clases y constructores en lugar de funciones, pero estoy tratando de usar una clase aquí.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!