Created
January 23, 2020 03:13
-
-
Save Eyas/239dbff2ffa7bc90faaa01fdf4ff0e28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Class { | |
// ... | |
private baseNode(skipDeprecatedProperties: boolean, context: Context): | |
TypeNode { | |
// ... | |
const parentNode = /* ... */; | |
const isRoot = parentNode === null; | |
const propLiteral = createTypeLiteralNode([ | |
// Add an '@id' property for the root. | |
...(isRoot ? [IdPropertyNode()] : []), | |
// ... then everything else. | |
...this.properties() | |
.filter(property => !property.deprecated || !skipDeprecatedProperties) | |
.map(prop => prop.toNode(context)) | |
]); | |
if (parentNode && propLiteral.members.length > 0) { | |
return createIntersectionTypeNode([parentNode, propLiteral]); | |
} else if (parentNode) { | |
return parentNode; | |
} else if (propLiteral.members.length > 0) { | |
return propLiteral; | |
} else { | |
return createTypeLiteralNode([]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment