runem / web-component-analyzer

CLI that analyzes web components and emits documentation
https://runem.github.io/web-component-analyzer
MIT License
501 stars 63 forks source link

Optional fields don't include `undefined` in their type. #145

Open justinfagnani opened 4 years ago

justinfagnani commented 4 years ago
export class TextField extends HTMLElement {
  size?: 'type'|'large';
}

The type is reported as "type": "\"type\" | \"large\"", but should be "type": "\"type\" | \"large\" | undefined".

runem commented 4 years ago

Is this a problem that you are experiencing when running the CLI or when using the analyzeText function?

Typescript strips undefined and null from the reported type if strictNullChecks is false, and it seems like I forgot to add it to compiler options when calling analyzeText:

https://github.com/runem/web-component-analyzer/blob/d8809c255c5f19b3ba63eafbbec7f0af5791a636/src/analyze/analyze-text.ts#L57-L62

runem commented 4 years ago

Is this still an issue, or did I fix it by adding strictNullChecks to compiler options for analyzeText?