Is there a type for Mirage.js's schema when working with Typescript

1.3k Views Asked by At

Am using mirage.js to mock an API that's not complete using typescript in strict mode. I am having trouble with the schema type in the routes() method.

It works, I just want to avoid the warning that comes with using any as the type.

A simple "endpoint" in the routes method

routes () {
  this.get(`todos`, (schema: any) => {
    return schema.todos.all();  
  });
}

I also tried to de structure the schema and getting the todos like so:

routes () {
  this.get(`todos`, ({ todos }) => {
    return todos.all();  
  });
}

But I didn't managed to find the type the todos should have.

Is there any solution to this issue other than using any?

Edit

A working codesandbox here: https://codesandbox.io/s/vue-5-typescript-forked-57h03m?file=/src/App.vue

Check folder named miragejs to see a more complete version of my code.

1

There are 1 best solutions below

0
IQbrod On

This is due to your typescript linter's configuration. You might remove the rule "typedef: arrow-parameter" in your tslint.json
Rules are explicitly declared, if you want to keep other benefits from the typedef rule, you will have to list them all, here's the one I personnaly use :

{
  ...
  "rules": {
    ...
    "typedef": [
      true,
      "call-signature",
      "parameter",
      "arrow-parameter", // Remove me
      "property-declaration",
      "variable-declaration",
      "variable-declaration-ignore-function",
      "member-variable-declaration",
      "object-destructuring",
      "array-destructuring"
    ]
  }
}

Here's the link to the documentation of typedef rule