[Question] How to create a TypeLiteral ?
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 238
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
Hello,
I'm trying to create a TypeAliasDeclaration with a TypeLiteral for the type attribute but it receives only a string or a function as value.
This an example of what I want to create
```typescript
export type Options = {
port?: number;
host?: string;
};
```
This is what I have currently
```typescript
sourceFile.addTypeAlias({
type: '{ port?: number; host?: number; }',
name: 'Options',
isExported: true,
});
```
Is there another way to achieve that ?

By doing something like this
```typescript
sourceFile.addTypeAlias({
type: new TypeLiteral({
propertySignatures: [
new PropertySignature({ hasQuestionToken: true, type: SyntaxKind.NumberKeyword, name: 'port' }),
new PropertySignature({ hasQuestionToken: true, type: SyntaxKind.StringKeyword, name: 'host' }),
]
}),
name: 'Options',
isExported: true,
});
```
Thanks.
Contributor guide
Assessment
This issue has not been assessed yet.