authzed / authzed-node

Official SpiceDB client library for NodeJS
https://authzed.com/docs/reference/api
Apache License 2.0
47 stars 18 forks source link

Typescript error on optional type. #54

Closed MadsKelberg closed 1 year ago

MadsKelberg commented 1 year ago

A typescript error is generated when using the v1.SubjectFilter type for the SubjectFilter. Property 'optionalSubjectId' is missing in type '{ subjectType: string; }' but required in type 'SubjectFilter'.ts(2741) permission_service.d.ts(115, 5): 'optionalSubjectId' is declared here.

The type in question that makes the issue is the optionalSubjectId, that is not optional according to the interface generated for v1.SubjectFilter.

There is a workaround by disabling semantic checks by using // @ts-nocheck at the beginning of the file. However this kind of defeats the purpose of using typescript.

josephschorr commented 1 year ago

Related to https://github.com/authzed/authzed-node/issues/53

samkim commented 1 year ago

@MadsKK Are you using .create to construct the v1.SubjectFilter message instances? That helper method allows you to omit optional fields when creating messages. Unfortunately, there is a disconnect between the name of that field and the semantics of the ts code generator.

See this comment for more context https://github.com/authzed/authzed-node/issues/33#issuecomment-1229068258

MadsKelberg commented 1 year ago

@samkim Okay, that seems to fix the problem. I was setting subjectFilter as a variable instead of setting it directly inside the .create function. It seems that everything just has to be created inside the .create function.

Thanks for the clarification :)

samkim commented 1 year ago

No problem, glad that worked!