Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Filter by
Sorted by
Tagged with
0 votes
0 answers
61 views

How can I programmatically detect template errors like "property does not exist"?

I have a simple Angular app: import { Component } from '@angular/core'; import { bootstrapApplication } from '@angular/platform-browser'; @Component({ selector: 'app-root', template: ` <...
Jon's user avatar
  • 455
0 votes
0 answers
53 views

How to Use Codemod with TS-Morph?

I want to use Codemod with TS-Morph to refactor TypeScript code, but I couldn't find any example code demonstrating how to do this. I found this article from Codemod stating that TS-Morph is supported,...
Jon's user avatar
  • 455
0 votes
0 answers
34 views

Can I Wrap `ts-morph` Functions in Promises for TypeScript Compatibility in Node.js?

I'm using ts-morph in a Node.js environment, but its synchronous functions are blocking the main thread, which causes issues with a terminal spinner (since the spinner also runs on the main thread in ...
Jon's user avatar
  • 455
0 votes
0 answers
54 views

Create an expression with ts-morph fails

I'm using AST/ts-morph to manipulate a React component const App = () => { return ( <Router> <Routes> <Route path="/" element={<...
Jeanluca Scaljeri's user avatar
1 vote
0 answers
87 views

How to extract ts type from record in ts-morph

I am trying to create a type tree from extracted types in a typescript file. I am using bun and ts-morph I can handle different types, like primitives, and some objects. But when trying to handle ...
programandoconro's user avatar
4 votes
1 answer
398 views

How to resolve imported types to their actual definition with ts-morph

I'm trying to see if its possible to use ts-morph to auto-generate documentation, for a few specific files. Assume I have the following file: import { SomeInterface } from 'some-module'; const ...
Ruben's user avatar
  • 1,819
0 votes
1 answer
53 views

How can I determine if a class member is a getter or setter?

I am trying to use ts-morph to validate code in a transpiler I am writing. No it is not a TypeScript transpiler, but I need to support both JS and TS code within my original file. I have the following ...
Intervalia's user avatar
  • 11.1k
0 votes
1 answer
91 views

Why `project.addSourceFilesAtPaths("../../tsconfig.json");` cannot get the correct result source files?

I use ts-morph to find all the source files: the key code: let tsmorph = require('ts-morph') const project = new tsmorph.Project(); project.addSourceFilesAtPaths("../../tsconfig.json"); ...
qg_java_17137's user avatar
7 votes
1 answer
4k views

How to use ts compiler api or ts-morph to get and serialize type information

I am trying to use the Typescript API to get information from typescript file that imports types from other sources. I got common type: // example.types.ts export interface Example<T> { ...
Firanolfind's user avatar
  • 1,605
2 votes
0 answers
563 views

How can I find which functions are being called by which functions with ts-morph or the typescript compiler API?

Using ts-morph, we can get function declarations in a source file by calling sourceFile.getFunctions(). Calling functionDeclaration.getChildrenOfKind(SyntaxKind.CallExpression) on function ...
guidupuy's user avatar
  • 525
1 vote
1 answer
379 views

Why ts-morph cannot get the classes of a typescript project?

I use ts-morph to analyse the classes inheritance relationship of a project: I download this opensource projectantv/x6 for testing: import { Project } from "ts-morph"; const project = new ...
qg_java_17137's user avatar
1 vote
1 answer
143 views

Type generation tool is not correctly handling nullable fields in TypeScript

I'm building a code generation tool that takes in an input file of my database schema as an interface and generates smaller types from that. Input export interface Database { public: { Tables: { ...
Barry Michael Doyle's user avatar
0 votes
1 answer
181 views

babel typescript interface convert to variable

There is Props interface from third-party: interface Props { id: string; name: string; age: number; approval: Approval } interface Approval { signature: string; } What is the solution that ...
riskers's user avatar
  • 179
1 vote
0 answers
56 views

How to get the next sibling and ignore tokens in ts-morph?

I try to get the next sibling using getNextSibling from ts-morph. The problem is I get the node DotToken or OpenBracketToken which I don't care about them. I want the node with the content. the ...
Jon Sud's user avatar
  • 11.9k
1 vote
0 answers
207 views

How to remove un used object literal using `ts-morph`?

I have a language file which exports the texts as object literal, export const lang = { hello : `hello`, calculate : (value = 0) => `the value is ${value}`, nested: { value: '...
JPS's user avatar
  • 2,760
2 votes
2 answers
758 views

How create TypeLiteral without string/writer when using ts-morph?

I want to create type files like this programatically: export type Car = { color: string; // ... tons of properties }; Thats seems pretty easy using ts-morph addTypeAlias method: sourceFile....
ajthinking's user avatar
  • 4,846
0 votes
0 answers
146 views

Get apparent type of NewExpression using ts-morph

I am currently trying to get the type of such declarations: const x = new BehaviourSubject<string>(); // Should be of type BehaviourSubject<string> Using ts-morph i tried: const declX = ...
Eti49's user avatar
  • 140
4 votes
0 answers
233 views

Is it possible to use ts-morph in eslint?

I want to use ts-morph in eslint. I ask that because I see when I create a plugin for eslint, eslint runs through all my files in my project each time. I mean when I have a Program selector then it ...
Jon Sud's user avatar
  • 11.9k
2 votes
0 answers
389 views

How to clone or detach node from the source using ts-morph?

I want to clone or detach node from typescript ast (using ts-morph). I explain what I mean using this example: I have two projects: const fooProject = new Project(); const barProject = new Project(); ...
Jon Sud's user avatar
  • 11.9k
0 votes
3 answers
3k views

How to compile typescript code along with C++?

I have a project which is completely in C++. Also I have one more file which is in typescript ( I wasn't able to find libraries equilvelent in C++). The typescript file is doing the following: 1 It ...
Senor Maldona's user avatar
0 votes
2 answers
170 views

How to use getPreviousSibling to get the node instead of getting syntax dot in ts-morph?

I am currently trying to resolve the "definition" of "Identifier". Note that I am using the ts-morph library. As an example, given the following source: const fn = () => {} ...
Jon Sud's user avatar
  • 11.9k
0 votes
2 answers
327 views

why getParentWhileKind in ts-morph not returns the expected parent of child?

I using ts-morph to analyze my code and I want to get the parent CallExpression from Identifier location. So I use .getParentWhileKind(SyntaxKind.CallExpression), but the function returns null. Why? ...
Jon Sud's user avatar
  • 11.9k
1 vote
1 answer
616 views

Can ts-morph work with typescript interface directly, not via files?

I need to extract from typescript interface into a js object. I have a function which does exactly that const getKeys = (intName: string): string[] => { const project = new Project(); const ...
Hayk's user avatar
  • 159
3 votes
1 answer
974 views

Resolving generic types based on implementation

I am currently trying to build a tool where i need to resolve generic types for my final output. Note that i am using the ts-morph library. As an example, given the following source and the ...
Eti49's user avatar
  • 140
1 vote
0 answers
293 views

Performance issue when generating a file with 'type-fest' import

I am trying to generate some source files using ts-morph, version 15.0.0. I am having performance issues that are somehow related to trying to generate an import from type-fest library. Without this ...
mrzli's user avatar
  • 17.5k
3 votes
0 answers
465 views

How to resolve the node items of array from the property in typescript compiler api and ts-morph?

I wondering if it's possible to get the nodes items of the array by using some method of typescript compiler api? In my code I pass NAMES array to names property and I can do it with different ways ...
Jon Sud's user avatar
  • 11.9k
3 votes
1 answer
535 views

How to access FlowNode in typescript ast api?

I try to resolve foo and bar from nodes variable. After I checked at ts-ast-viewer you can see in the picture that typescript can know about foo and bar from nodes node, under FlowNode section. (node -...
Jon Sud's user avatar
  • 11.9k
0 votes
1 answer
1k views

How to get the value of a (TypeScript) template literal type programatically?

I'm trying to get the value of a template literal type. I know I have to parse the source file for this. I am using ts-morph right now which basically extends the programmatic API of the TypeScript ...
Bart Louwers's user avatar
2 votes
0 answers
1k views

Critical dependency: the request of a dependency is an expression, @ts-morph/common/dist/typescript.js npx create-react-app

I was trying to import, import { createProject, ts } from "@ts-morph/bootstrap"; But every time built failed, due to complied with warnings, Compiled with warnings. ./node_modules/@ts-morph/...
sp_kolinfure's user avatar
3 votes
2 answers
581 views

Add a component in declarations NgModule using ts-morph

I'm using ts-morph library and I want to insert in the declarations a component: This is what I have: @NgModule({ declarations: [], imports: [], providers: [], }) This is what I want: @NgModule({ ...
lili-code's user avatar
1 vote
1 answer
1k views

ts-morph - how to insert into existing constructor template within main class

I am a beginner at TS manipulation with ts-morph. I have a template of existing source file, and i wanted to continue building up the template within the constructor space within the main class. cdk-...
unacorn's user avatar
  • 1,100
1 vote
0 answers
335 views

Generate fat arrow function property assignment in ts-morph

I want to generate code like this using ts-morph. const obj = { func: (arg: number) => 3 } I have the ObjectLiteralExpression already and need to add it. I'm guessing through addProperty or ...
eltiare's user avatar
  • 1,948
2 votes
3 answers
2k views

how to get an object literal properties with ts-morph

I am parsing a file like this using ts-morph const a = {property1: 20, property2: 30} I can't seem to figure out how to get an ObjectLiteralExpression mentioned here https://ts-morph.com/details/...
SoWhat's user avatar
  • 5,622
1 vote
1 answer
172 views

The easiest way to compare two imports of different formats

I'm in the process of writing Jest unit test and need to compare two imports: import { StoreFinderMapComponent } from '@spartacus/storefinder/components' and import StoreFinderMapComponent from "@...
Mirosław Grochowski's user avatar
3 votes
0 answers
148 views

Do I need ts-morph or tailwindcss for an Electron production build?

I am packaging my first Electron app. I noticed a lot of modules inside the app.asar of my Electron app and I don't think they should be in there. AFAIK it's a dev dependency but ends up in the ...
Daniel Stephens's user avatar
1 vote
1 answer
2k views

typescript, ts-morph module, is there access to underlying `ts.SourceFile` instance from a `ts-morph.SourceFile` instance?

I am trying out the ts-morph npm module to replace some code which I have already written but which overlaps ts-morph and is inferior. Nevertheless, I have some existing functions that take an ts....
Craig  Hicks's user avatar
  • 2,658
2 votes
1 answer
2k views

TS-Morph, Is it possible to manipulate block Node to add statements?

I want to dynamically add statements inside an async arrow function inside a class; I read the documentation and I didn't find anything that could help me, I was only able to get the block node where ...
Ben Rhouma Zied's user avatar