Can ts-morph work with typescript interface directly, not via files?
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 238
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
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 sourceFile = project.addSourceFileAtPath(`./${path}/${intName}.ts`);
const node = sourceFile.getInterface(intName)!;
const allKeys = node.getProperties().map((p) => p.getName());
return allKeys;
};
```
But the problem is, that it requires the interface to be the default export of a seperate file. Ideally i want to provide this function not the file address, but the interface itself, it might look something like this
`getKeys()`
Is this possible to do with ts-morph?
Contributor guide
Research direction
Start by reviewing the Project, addSourceFileAtPath, getInterface, and interface-node APIs used in the getKeys example. Determine whether the requested interface input fits an existing entry point or requires a broader API design; done means the supported approach is documented and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100