E406 Params.user type · Issue #2157 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content

Params.user type #2157

@bwgjoseph

Description

@bwgjoseph

Hi, this PR actually break some of my stuff.. not sure if there's better way.. #2090

This is what I currently have in 4.5.9

interface User {
  _id: string;
  name: string;
  email: string;
  // and so on
}

const getUserId = (user: User) => user._id ?? 'default';

// in some of my hook, I will grab the user from the params or return the default name
const userId = getUserId(params.user);

But with the upgrade, it now breaks in places where I pass in params.user

// because of the new addition
// it now complains.. 
// Argument of type '{ [key: string]: any; } | undefined' is not assignable to parameter of type 'User'.
// Type 'undefined' is not assignable to 'User'

I can do this but then I have to go all over to make the changes

const userId = getUserId(params.user as User);

Is there a better way to do this?

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

      0