• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

379
Views
¿Cómo debo hacer para obtener el texto ts cuando uso la API transpileModule?

Utilizo transpileModule para insertar un campo en Page-data , pero obtengo el resultado es un texto js, pierdo interface Account y opt: string | any ¿Cómo puedo hacer para obtener ts text?

 const ts = require('typescript') const factory = ts.factory const content = ` interface Account { id: number displayName: string version: 1 } Page({ data: { name: 'miser', }, }) Component({ data: { age: 18, }, }) function Component(opt: string | any) {} function Page(opt: any) {} ` const result = ts.transpileModule(content, { compilerOptions: {}, transformers: { before: [visitNodes], }, }) function visitNodes(ctx) { const visitor = node => { if ( ts.isPropertyAssignment(node) && node.name.escapedText === 'data' && node.parent.parent.expression.escapedText === 'Page' ) { const newNode = factory.createPropertyAssignment('haha', factory.createStringLiteral('ok')) node.initializer.properties.push(newNode) } return ts.visitEachChild(node, visitor, ctx) } return sourceFile => ts.visitNode(sourceFile, visitor) } console.log(result.outputText) // Page({ // data: { // name: 'miser', // haha: "ok", // }, // }); // Component({ // data: { // age: 18, // }, // }); // function Component(opt) { } // function Page(opt) { }
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error