Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to pass multiple groups to setUserObjectColors #1290

Closed
gouldingken opened this issue Jan 9, 2023 · 5 comments
Closed

Unable to pass multiple groups to setUserObjectColors #1290

gouldingken opened this issue Jan 9, 2023 · 5 comments
Labels
bug Something isn't working [ viewer ] issues related to the 3d viewer package

Comments

@gouldingken
Copy link

It's unclear if this is a bug or documentation issue (or user error), but I'm having trouble using the setUserObjectColors method:

setUserObjectColors(groups: [{ objectIds: string[]; color: string }])

I'm not familiar with that TS syntax. If this is an array of objects that contain objectIds and a color, should that not be written as follows?:

groups: { objectIds: string[]; color: string }[]

The TS error I'm getting when I try to pass more than 1 element through is:

TS2345: Argument of type '[{ objectIds: string[]; color: string; }, { objectIds: string[]; color: string; }]' is not assignable to parameter of type '[{ objectIds: string[]; color: string; }]'.   Source has 2 element(s) but target allows only 1.

I've tried using the exact code specified in #1205 - but got the error above.

@gouldingken gouldingken added the bug Something isn't working label Jan 9, 2023
@AlexandruPopovici
Copy link
Contributor

Hi @gouldingken

setUserObjectColors takes a single parameter which needs to be an array.
Each element of that array needs to be of type:

{
  objectIds: string[]
  color: string
}

The groups parameter is an array, because this way you can provide multiple user colors to groups of ids in a single call. If you want to set a user color to a single group of ids, you can call it with a single element array like so:

setUserObjectColors([
  {
    objectIds: [
      'id1',
      'id2',
      'id3',
      'id4'
    ],
    color: '#8b5cf6'
  }
])

@gouldingken
Copy link
Author

That works. But it still throws the TypeScript error. I think you just need to fix the type syntax.

@AlexandruPopovici
Copy link
Contributor

AlexandruPopovici commented Jan 20, 2023

From the error you are getting in you initial comment:
[{ objectIds: string[]; color: string; }, { objectIds: string[]; color: string; }]

The type you are trying to assign is incorrect and it's not what setUserObjectColors expects as it's argument type. The error message explains what is wrong accurately
Alternatively, please post some context and your exact call to setUserObjectColors

@gouldingken
Copy link
Author

gouldingken commented Jan 20, 2023

I have the code working fine. I just have to disable the type checking.

I'm pretty sure it's just that the first '[' needs to come after the object type, not before.

If this were expecting an array of numbers, you'd write it as number[], not [number], right?

@didimitrie
Copy link
Member

This might becoming a typescript lesson for all of us (especially me!) I think i wrote that function (?) and my intention was pass in a non-empty array not pass in an array of one object. I'm happy to defer to whatever signature is needed there, and we can also skip the non-empty array part; ie it can be just { objectIds: string[]; color: string; }[] - if i got my typescript right :D

@AlexandruPopovici AlexandruPopovici added the [ viewer ] issues related to the 3d viewer package label May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working [ viewer ] issues related to the 3d viewer package
Projects
None yet
Development

No branches or pull requests

3 participants