arjun-g / vs-swagger-viewer

Swagger Viewer lets you preview and validate Swagger 2.0 and OpenAPI files as you type in Visual Studio Code.
MIT License
169 stars 47 forks source link

Missing type coercion makes `npm run vscode:prepublish` fail #93

Closed tchernobog closed 2 years ago

tchernobog commented 3 years ago

https://github.com/arjun-g/vs-swagger-viewer/blob/894d09b4e0f1dba5c06032e5bea785f18f74017c/src/preview/client.ts#L99

This line makes prepublish fail with:

$ npm run vscode:prepublish

> swagger-viewer@3.0.1 vscode:prepublish /home/matteo/temp/vs-swagger-viewer
> tsc -p ./

src/preview/client.ts:101:30 - error TS2339: Property 'swagger' does not exist on type 'string | object'.
  Property 'swagger' does not exist on type 'string'.

101               if (parsedYAML.swagger === "2.0") {
                                 ~~~~~~~

src/preview/client.ts:104:28 - error TS2339: Property 'openapi' does not exist on type 'string | object'.
  Property 'openapi' does not exist on type 'string'.

104                 parsedYAML.openapi &&
                               ~~~~~~~

src/preview/client.ts:105:28 - error TS2339: Property 'openapi' does not exist on type 'string | object'.
  Property 'openapi' does not exist on type 'string'.

105                 parsedYAML.openapi.match(/^3\.0\.\d(-.+)?$/)
                               ~~~~~~~

Found 3 errors.

An easy fix is to coerce this type to any. For instance: const parsedYAML = <any>YAML.safeLoad(document.getText());