Skip to content

Cannot find name 'Nullable' #79

Closed
@streusselhirni

Description

@streusselhirni

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions