Skip to content

How to get type inference? #223

@vittis

Description

@vittis

I might be missing something trivial, but here's my case:

// define schema
const roomSchema = new Schema("room", {
  id: { type: "string" },
  name: { type: "string" },
  members: { type: "string[]" },
});

// somewhere in code...
const room = await roomRepository.fetch(roomId);
if (room.members.includes(session.userId)) { // ts-error here 
    // ...
}

The error is:

Property 'includes' does not exist on type 'string | number | true | Date | EntityData | Point | (EntityData | EntityDataValue)[] | (EntityData | EntityDataValue)[]'.

That is because looks like there's no type inference. When I type "room." the properties doesn't show up. I tried creating a interface for Room and tried plugging into generics or casting but nothing worked...

I could check if room.members exists and then check if its type is array, is that what I'm supposed to do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions