Skip to content

Commit 090b725

Browse files
committed
refactor: replace type-aliases with interfaces
1 parent b4ef46c commit 090b725

File tree

6 files changed

+143
-125
lines changed

6 files changed

+143
-125
lines changed

src/fileReader.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as yaml from 'js-yaml';
22

3-
export type JSON = {
4-
[key: string]: unknown;
5-
};
3+
export interface JSON extends Record<string, unknown> {}
64
export type FileReader = (buffer: Buffer) => JSON;
75

86
export const fromJSON: FileReader = buffer => JSON.parse(buffer.toString());

src/fs.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import * as fs from 'fs-extra';
22
import * as path from 'path';
33

4-
export type File = {
4+
export interface File {
55
type: 'FILE';
66
name: string;
77
content: string;
8-
};
8+
}
99

1010
export const file = (name: string, content: string): File => ({
1111
type: 'FILE',
1212
name,
1313
content,
1414
});
1515

16-
export type Directory = {
16+
export interface Directory {
1717
type: 'DIRECTORY';
1818
name: string;
1919
content: FSEntity[];
20-
};
20+
}
2121

2222
export const directory = (name: string, content: FSEntity[]): Directory => ({
2323
type: 'DIRECTORY',
@@ -27,10 +27,10 @@ export const directory = (name: string, content: FSEntity[]): Directory => ({
2727

2828
export type FSEntity = File | Directory;
2929

30-
export type BufferWithName = {
30+
export interface BufferWithName {
3131
buffer: Buffer;
3232
fileName: string;
33-
};
33+
}
3434

3535
export const write = async (destination: string, entity: FSEntity): Promise<void> => {
3636
switch (entity.type) {

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { PathReporter } from 'io-ts/lib/PathReporter';
1515

1616
const log = console.log.bind(console, '[SWAGGER-CODEGEN-TS]:');
1717

18-
export type GenerateOptions = {
18+
export interface GenerateOptions {
1919
/**
2020
* Paths to spec files
2121
*/
@@ -37,7 +37,7 @@ export type GenerateOptions = {
3737
* @param buffer - File Buffer
3838
*/
3939
fileReader: FileReader;
40-
};
40+
}
4141

4242
const cwd = process.cwd();
4343
const resolvePath = (p: string) => (path.isAbsolute(p) ? p : path.resolve(cwd, p));

src/language/typescript.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,28 @@ const concatIf = <A>(condition: boolean, as: A[], a: A[]): A[] => concatIfL(cond
5858
const unless = (condition: boolean, a: string): string => (condition ? '' : a);
5959
const when = (condition: boolean, a: string): string => (condition ? a : '');
6060

61-
type Dependency = {
61+
interface Dependency {
6262
name: string;
6363
path: string;
64-
};
65-
type SerializedType = {
64+
}
65+
66+
interface SerializedType {
6667
type: string;
6768
io: string;
6869
dependencies: Dependency[];
6970
refs: string[];
70-
};
71+
}
72+
7173
const serializedType = (type: string, io: string, dependencies: Dependency[], refs: string[]): SerializedType => ({
7274
type,
7375
io,
7476
dependencies,
7577
refs,
7678
});
7779

78-
type SerializedParameter = SerializedType & {
80+
interface SerializedParameter extends SerializedType {
7981
isRequired: boolean;
80-
};
82+
}
8183
const serializedParameter = (
8284
type: string,
8385
io: string,
@@ -91,9 +93,9 @@ const serializedParameter = (
9193
dependencies,
9294
refs,
9395
});
94-
type SerializedPathParameter = SerializedParameter & {
96+
interface SerializedPathParameter extends SerializedParameter {
9597
name: string;
96-
};
98+
}
9799
const serializedPathParameter = (
98100
name: string,
99101
type: string,
@@ -217,9 +219,9 @@ const serializePathGroup = (name: string, group: Record<string, PathItemObject>,
217219
`
218220
${dependencies}
219221
220-
export type ${groupName} = {
222+
export interface ${groupName} {
221223
${serialized.type}
222-
};
224+
}
223225
224226
export const ${decapitalize(groupName)} = asks((e: { apiClient: APIClient }): ${groupName} => ({
225227
${serialized.io}
@@ -771,17 +773,17 @@ const client = `
771773
import { report } from '../utils/utils';
772774
import { left } from 'fp-ts/lib/Either';
773775
774-
export type APIRequest = {
776+
export interface APIRequest {
775777
url: string;
776778
query?: object;
777779
body?: unknown;
778780
};
779781
780-
export type FullAPIRequest = APIRequest & {
782+
export interface FullAPIRequest extends APIRequest {
781783
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
782784
};
783785
784-
export type APIClient = {
786+
export interface APIClient {
785787
readonly request: (request: FullAPIRequest) => LiveData<Error, mixed>;
786788
};
787789

0 commit comments

Comments
 (0)