authzed/authzed-node

Typescript error on optional type.

Closed this issue · 4 comments

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.

Related to #53

@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 #33 (comment)

@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 :)

No problem, glad that worked!