1

i want to generate interface to string. example

interface cat {
    id : number
    name : string
}
const output = convertInterfaceToString(cat) 

my expect output should be a string exactly like this " interface cat { id : number name : string } "

My purpose is to generate an interface as a string in my project and then save it to a file (e.g., somefile.ts). This way, I can use it in another project without the need for manual copying and parsing.

is it possible in typescript? thankyou.

2
  • Why you want to create as string, why copy entire file from 1 project to another. Commented Dec 22, 2023 at 11:44
  • This is not possible in TypeScript directly. You'd need some other build step that looks at your source code and does something with it. TypeScript interfaces are erased along with the rest of the static type system, so there's nothing you can use to create the string you're looking for. Commented Dec 22, 2023 at 13:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.