Skip to content

Commit 4f2d3da

Browse files
j-xzydomoritz
authored andcommitted
support never (YousefED#308)
1 parent 17f2276 commit 4f2d3da

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

test/programs/never/main.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface Never {
2+
neverProp: never;
3+
propA: string;
4+
}

test/programs/never/schema.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"properties": {
4+
"propA": {
5+
"type": "string"
6+
}
7+
},
8+
"required": [
9+
"propA"
10+
],
11+
"type": "object"
12+
}

test/schema.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ describe("schema", () => {
230230
// see https://github.com/epoberezkin/ajv/issues/725
231231
// assertSchema("type-function", "MyObject");
232232
assertSchema("any-unknown", "MyObject");
233+
assertSchema("never", "Never");
233234
});
234235

235236
describe("class and interface", () => {

typescript-json-schema.ts

+5
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,11 @@ export class JsonSchemaGenerator {
711711

712712
const clazz = <ts.ClassDeclaration>node;
713713
const props = this.tc.getPropertiesOfType(clazzType).filter(prop => {
714+
// filter never
715+
const propertyType = this.tc.getTypeOfSymbolAtLocation(prop, node);
716+
if (ts.TypeFlags.Never === propertyType.getFlags()) {
717+
return false;
718+
}
714719
if (!this.args.excludePrivate) {
715720
return true;
716721
}

0 commit comments

Comments
 (0)