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

129
Views
extendiendo http.IncomingMessage y http.ServerResponse y proporcionándolo a http.createServer. ¿Cómo hacer eso en TS?

Quiero proporcionar mi propia clase personalizada http.IncomingMessage y http.ServerResponse a http.createServer(opt,fn) . He estado buscando durante aproximadamente 2 horas para encontrar una forma de escribir esto en mecanografiado. Pero no ayudó. Pero este mismo código funciona en JS. Por favor, ayúdame . Solo quiero proporcionar un objeto de solicitud y respuesta personalizado a http.createServer() .

Aquí está mi archivo server.js JAVASCRIPT.

 const { createServer, IncomingMessage, ServerResponse } = require("http"); class Request extends IncomingMessage { constructor(socket) { super(socket); } getMeAnything() { return "you got REQUEST"; } } class Response extends ServerResponse { constructor(req) { super(req); } getMeAnything() { return "you got RESPONSE"; } } const server = createServer( { IncomingMessage: Request, ServerResponse: Response, }, (req, res) => { console.log(req.getMeAnything()); res.end("Hello How are you ?"); } ); server.listen(3000);

aquí está mi archivo server.ts TYPESRIPT:

 import { Socket } from "net"; import { createServer, IncomingMessage, ServerResponse } from "http"; class Req extends IncomingMessage { constructor(socket: Socket) { super(socket); } getMeAnything() { return "you got anything inside REQUEST"; } } class Res extends ServerResponse { constructor(req: IncomingMessage) { super(req); } getMeAnything() { return "you got anything inside RESPONSE"; } } const server = createServer( { IncomingMessage: Req, ServerResponse: Res, }, (req: Req, res: Res) => { // here I get a big fat error . Some suggested me to write @ts-ignore . But I think there is a solution for it . console.log(req.getMeAnything()); res.end("Hello How are you ?"); } ); server.listen(3000);

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!