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

Cannot find name 'Nullable' #79

Closed
streusselhirni opened this issue Apr 11, 2020 · 0 comments · Fixed by #80
Closed

Cannot find name 'Nullable' #79

streusselhirni opened this issue Apr 11, 2020 · 0 comments · Fixed by #80

Comments

@streusselhirni
Copy link

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

  1. 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"
          ]
        }
      }
    }
  }
}
  1. Add api-doc-parser to dependencies with yarn add @api-platform/api-doc-parser (or npm install @api-platform/api-doc-parser

  2. 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);
  }

  1. Run yarn serve (or npm run serve)

  2. The errors show up in the console:

screenshoot

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant