Closed
Description
API Platform version(s) affected: 0.8.2
Description
When using api-doc-parser in a Project set up with VueCLI with Typescript, I get the compile error Cannot find name 'Nullable'
in the following files:
- Api.d.ts
- Field.d.ts
- Operation.d.ts
- Resource.d.ts
How to reproduce
- Create Project with VueCLI using this Preset
{
"useTaobaoRegistry": false,
"packageManager": "yarn",
"latestVersion": "4.3.1",
"lastChecked": 1586624138305,
"presets": {
"api-doc-parser-preset": {
"useConfigFiles": true,
"plugins": {
"@vue/cli-plugin-babel": {},
"@vue/cli-plugin-typescript": {
"classComponent": true,
"useTsWithBabel": true
},
"@vue/cli-plugin-eslint": {
"config": "airbnb",
"lintOn": [
"save"
]
}
}
}
}
}
-
Add api-doc-parser to dependencies with
yarn add @api-platform/api-doc-parser
(ornpm install @api-platform/api-doc-parser
-
Add the following code to the generated
App.vue
file between the<script lang="ts"></script>
tags:
import { Component, Vue } from 'vue-property-decorator';
import HelloWorld from './components/HelloWorld.vue';
import parseHydraDocumentation
from '@api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation';
@Component({
components: {
HelloWorld,
},
})
export default class App extends Vue {
async mounted() {
const docs = parseHydraDocumentation('http://localhost:8000/api');
console.log(docs);
}
-
Run
yarn serve
(ornpm run serve
) -
The errors show up in the console:
Possible Solution
I managed to work around this issue by creating a global.d.ts
file, making sure it is used by deleting the types
key in tsconfig.json
and adding the following code in global.d.ts
:
type Nullable<T> = {
[P in keyof T]: T[P] | null
}
Metadata
Metadata
Assignees
Labels
No labels