question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

include option typescript type check doesn't accept strings

See original GitHub issue

What are you doing?

class User extends Model {
}

User.belongsTo(Country)

User.findAll({include: ['Country']}) // => raises error
User.findAll({include: ['Country'] as any}) // =>  works fine

What do you expect to happen?

No error in the first call.

What is actually happening?

lib/models/index.ts:17:19 - error TS2345: Argument of type '{ include: string[]; }' is not assignable to parameter of type 'FindOptions'.
  Types of property 'include' are incompatible.
    Type 'string[]' is not assignable to type 'Includeable[]'.
      Type 'string' is not assignable to type 'Includeable'.

Environment

Sequelize version: 5.9.0 Node Version: 8 OS: Mojave 10.14.5 If TypeScript related: 3.4.4

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bogdancommented, Jul 26, 2019

I think that it is ambiguous to specify two option instead of one. I feel myself in nineties when I see that: back then people had to understand machines. Right now, if a software knows what I mean it just does that without asking additional questions aka options.

Woundn’t it be so much easier to read:

findAll({include: ['children', 'parent']})
// then
findAll({include: [{model: Comment, as: 'children'}, {model: Comment, as: 'parent'}])

<OFFTOPIC> I don’t even tell you how much easier it would be to have this then its expanded nested hashes equivalent:

findAll({include: {parent: ['parent'], children: ['children']}) 
// suppose to load parent of a parent and children of children

But that is a story for another time.

0reactions
ephyscommented, Apr 16, 2022

This has since been resolved, the issue isn’t present in Sequelize 6 anymore

I also agree that specifying the name of the association:

include: ['children']
// or if you need more options
include: [{ association: 'children', ... other options }]

is generally better than specifying a model+as pair:

include: [{ model: User, as: 'children' }]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'includes' does not exist on type 'string[]'
The includes method on Array is supported since ES7 (ES2016). The above will add a missing library ... The TypeScript compiler options are...
Read more >
Documentation - Advanced Types - TypeScript
This page lists some of the more advanced ways in which you can model types, it works in tandem with the Utility Types...
Read more >
Documentation - Everyday Types - TypeScript
In this chapter, we'll cover some of the most common types of values you'll find in JavaScript code, and explain the corresponding ways...
Read more >
Documentation - Do's and Don'ts - TypeScript
Don't ever use the types Number , String , Boolean , Symbol , or Object These types ... Don't ever have a generic...
Read more >
Documentation - Narrowing - TypeScript
Since string is the only common type that both x and y could take on, TypeScript knows that x and y must be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found