-
Notifications
You must be signed in to change notification settings - Fork 0
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
make project schema properties optional #133
Conversation
src/lib/encode-converstions.ts
Outdated
@@ -21,24 +21,25 @@ type ConvertFunction<TSchemaName extends SchemaName> = ( | |||
> | |||
) => CurrentProtoTypes[TSchemaName] | |||
|
|||
/* @ts-ignore TODO: resolve "not assignable to type 'ConvertFunction<"project">" */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
full output of the error:
error TS2322:
Type '(mapeoDoc: Omit<{ schemaName: "project"; name?: string | undefined; defaultPresets?: { point?: string[] | undefined; area?: string[] | undefined; vertex?: string[] | undefined; line?: string[] | undefined; relation?: string[] | undefined; } | undefined; ... 4 more ...; links: string[]; }, "versionId">) => { ...; }'
is not assignable to type 'ConvertFunction<"project">'.
Call signature return types '{ defaultPresets: { point: Buffer[]; area: Buffer[]; vertex: Buffer[]; line: Buffer[]; relation: Buffer[]; }; name?: string | undefined; docId: string; links: string[]; createdAt: string; updatedAt: string; schemaName: "project"; common: Common_1 | undefined; }'
and 'Project_2' are incompatible.
The types of 'name' are incompatible between these types.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types from protobuf are quite confusing. Every field in protobuf is optional, but the decoder defaults to settings undefined fields as an empty string / false / 0, unless fields are marked optional
.
Fixed this by defining name
and defaultPresets
as optional in the proto file.
@@ -21,24 +21,25 @@ type ConvertFunction<TSchemaName extends SchemaName> = ( | |||
> | |||
) => CurrentProtoTypes[TSchemaName] | |||
|
|||
/* @ts-ignore TODO: resolve "not assignable to type 'ConvertFunction<"project">" */ | |||
export const convertProject: ConvertFunction<'project'> = (mapeoDoc) => { | |||
return { | |||
common: convertCommon(mapeoDoc), | |||
...mapeoDoc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...mapeoDoc, | |
...mapeoDoc, | |
name: mapeoDoc.name || '', |
I think that since name
is now optional, we need to take that into account here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the protobuf definition to allow for optional values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right! forgot about that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made some changes, updated the test, and a fix for the type issue. Looks good to me.
@@ -21,24 +21,25 @@ type ConvertFunction<TSchemaName extends SchemaName> = ( | |||
> | |||
) => CurrentProtoTypes[TSchemaName] | |||
|
|||
/* @ts-ignore TODO: resolve "not assignable to type 'ConvertFunction<"project">" */ | |||
export const convertProject: ConvertFunction<'project'> = (mapeoDoc) => { | |||
return { | |||
common: convertCommon(mapeoDoc), | |||
...mapeoDoc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the protobuf definition to allow for optional values
src/lib/encode-converstions.ts
Outdated
@@ -21,24 +21,25 @@ type ConvertFunction<TSchemaName extends SchemaName> = ( | |||
> | |||
) => CurrentProtoTypes[TSchemaName] | |||
|
|||
/* @ts-ignore TODO: resolve "not assignable to type 'ConvertFunction<"project">" */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types from protobuf are quite confusing. Every field in protobuf is optional, but the decoder defaults to settings undefined fields as an empty string / false / 0, unless fields are marked optional
.
Fixed this by defining name
and defaultPresets
as optional in the proto file.
This removes
name
anddefaultPresets
from the required array of the project jsonschemas.There's one type error that I've ts-ignored that I'm not sure how to deal with. See the comment below.