Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Denote the optional aspect of types when describing them #159

Merged
merged 2 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/jsii-spec/lib/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,20 +569,27 @@ export function isClassOrInterfaceType(type: Type): type is (InterfaceType | Cla
export function describeTypeReference(a?: TypeReference): string {
if (a === undefined) { return '(none)'; }

const optionalMarker = a.optional ? '?' : '';

if (isNamedTypeReference(a)) {
return a.fqn;
return `${a.fqn}${optionalMarker}`;
}

if (isPrimitiveTypeReference(a)) {
return a.primitive;
return `${a.primitive}${optionalMarker}`;
}

if (isCollectionTypeReference(a)) {
return `${a.collection.kind}<${describeTypeReference(a.collection.elementtype)}>`;
return `${a.collection.kind}<${describeTypeReference(a.collection.elementtype)}>${optionalMarker}`;
}
if (isUnionTypeReference(a)) {
return a.union.types.map(describeTypeReference).join('|');
const unionType = a.union.types.map(describeTypeReference).join(' | ');
if (a.optional) {
return `(${unionType})${optionalMarker}`;
} else {
return unionType;
}
}

throw new Error('Unrecognized type reference');
}
}
2 changes: 1 addition & 1 deletion packages/jsii/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": false, /* Emit a single file with source maps instead of having a separate file. */
"inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My own debugger experience... We can actually inline the original source, so that random customers debugging with source map support enabled get to see the typescript too. Or do you want this particular change removed?

// "inlineSources": false, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
Expand Down