Skip to content

Commit 9f2028b

Browse files
committedAug 20, 2020
fix(): align with the rest of codebase
1 parent 766956e commit 9f2028b

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed
 

‎lib/plugin/visitors/model-class.visitor.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ export class ModelClassVisitor extends AbstractFileVisitor {
204204
const remainingTypes = node.types.filter(
205205
(item) => item !== nullableType
206206
);
207-
/**
208-
* when we have more than 1 type left, we could use oneOf
209-
*/
207+
208+
// When we have more than 1 type left, we could use oneOf
210209
if (remainingTypes.length === 1) {
211210
const remainingTypesProperties = this.createTypePropertyAssignments(
212211
remainingTypes[0],

‎test/plugin/model-class-visitor.spec.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,6 @@ import {
2222
} from './fixtures/nullable.dto';
2323

2424
describe('API model properties', () => {
25-
it('should understand nullable', () => {
26-
const options: ts.CompilerOptions = {
27-
module: ts.ModuleKind.ESNext,
28-
target: ts.ScriptTarget.ESNext,
29-
newLine: ts.NewLineKind.LineFeed,
30-
noEmitHelpers: true,
31-
strict: true
32-
};
33-
const filename = 'nullable.dto.ts';
34-
const fakeProgram = ts.createProgram([filename], options);
35-
36-
const result = ts.transpileModule(nullableDtoText, {
37-
compilerOptions: options,
38-
fileName: filename,
39-
transformers: {
40-
before: [before({ classValidatorShim: true }, fakeProgram)]
41-
}
42-
});
43-
expect(result.outputText).toEqual(nullableDtoTextTranspiled);
44-
});
45-
4625
it('should add the metadata factory when no decorators exist', () => {
4726
const options: ts.CompilerOptions = {
4827
module: ts.ModuleKind.ESNext,
@@ -126,4 +105,25 @@ describe('API model properties', () => {
126105
});
127106
expect(result.outputText).toEqual(es5CreateCatDtoTextTranspiled);
128107
});
108+
109+
it('should support & understand nullable type unions', () => {
110+
const options: ts.CompilerOptions = {
111+
module: ts.ModuleKind.ESNext,
112+
target: ts.ScriptTarget.ESNext,
113+
newLine: ts.NewLineKind.LineFeed,
114+
noEmitHelpers: true,
115+
strict: true
116+
};
117+
const filename = 'nullable.dto.ts';
118+
const fakeProgram = ts.createProgram([filename], options);
119+
120+
const result = ts.transpileModule(nullableDtoText, {
121+
compilerOptions: options,
122+
fileName: filename,
123+
transformers: {
124+
before: [before({ classValidatorShim: true }, fakeProgram)]
125+
}
126+
});
127+
expect(result.outputText).toEqual(nullableDtoTextTranspiled);
128+
});
129129
});

0 commit comments

Comments
 (0)
Please sign in to comment.