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

Fix macro for inherited types to avoid typescript error #76

Closed
wants to merge 1 commit into from

Conversation

zzorba
Copy link
Collaborator

@zzorba zzorba commented Aug 19, 2024

I believe this will address #75

@zzorba zzorba requested a review from jhugman August 19, 2024 20:36
@zzorba zzorba force-pushed the dsalinas/fix_macro_for_inherited_types branch from 3ca1b10 to 1cdf6fd Compare August 19, 2024 20:55
@zzorba
Copy link
Collaborator Author

zzorba commented Aug 19, 2024

Basically our exporting trick has one problem, microsoft/TypeScript#30355

So I marked them public and put a strongly worded note on the fields in question. We could also suppress the typescript warning, but it has to be done at each export site (annoying)

Copy link
Owner

@jhugman jhugman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some nits and a question, but nothing that should warrant a second review cycle. Good job! Thanks for stepping in for this.

* This member should be private, but typescript requires
* it be public because it cannot enforce it.
*/
public readonly __variant: number
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prettier wants a trailing comma.

* it be public because it cannot enforce it.
*/
public readonly __variant: number,
message?: string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prettier wants a trailing comma.

@@ -26,7 +38,7 @@ export class UniffiError extends Error {
return UniffiError.createMessage(
this.__uniffiTypeName,
this.__variantName,
this.message,
this.message
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prettier wants a trailing comma.

@@ -54,7 +66,7 @@ export class UniffiThrownObject<T> extends Error {
constructor(
private readonly __uniffiTypeName: string,
public readonly inner: T,
message?: string,
message?: string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prettier wants a trailing comma.

@@ -66,7 +78,7 @@ export class UniffiThrownObject<T> extends Error {
return UniffiThrownObject.createMessage(
this.__uniffiTypeName,
this.inner,
this.message,
this.message
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prettier wants a trailing comma.

@@ -108,7 +120,7 @@ export const UniffiInternalError = (() => {
class BufferOverflow extends Error {
constructor() {
super(
"Reading the requested value would read past the end of the buffer",
"Reading the requested value would read past the end of the buffer"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prettier wants a trailing comma.

@@ -145,14 +157,14 @@ export const UniffiInternalError = (() => {
class ContractVersionMismatch extends Error {
constructor(rustVersion: any, bindingsVersion: any) {
super(
`Incompatible versions of uniffi were used to build the JS ($${bindingsVersion}) from the Rust (${rustVersion})`,
`Incompatible versions of uniffi were used to build the JS ($${bindingsVersion}) from the Rust (${rustVersion})`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prettier wants a trailing comma.

);
}
}
class ApiChecksumMismatch extends Error {
constructor(func: string) {
super(
`FFI function ${func} has a checksum mismatch; this may signify previously undetected incompatible Uniffi versions`,
`FFI function ${func} has a checksum mismatch; this may signify previously undetected incompatible Uniffi versions`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prettier wants a trailing comma.

@@ -37,7 +49,7 @@ export class UniffiError extends Error {
private static createMessage(
typeName: string,
variantName: string,
message: string | undefined,
message: string | undefined
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prettier wants a trailing comma.

Comment on lines +14 to +28
/*
* This member should be private, but typescript requires
* it be public because it cannot enforce it.
*/
public readonly __uniffiTypeName: string,
/*
* This member should be private, but typescript requires
* it be public because it cannot enforce it.
*/
public readonly __variantName: string,
/*
* This member should be private, but typescript requires
* it be public because it cannot enforce it.
*/
public readonly __variant: number,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this would be better as private properties in the generated subclasses rather than the super class.

My hunch is that the DX of having __ properties turn up in autocomplete becomes annoying after a while.

WDYT? Is that annoyance a non-issue, or is it worth the extra work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be better, and they should still be accessible on the union type we're creating. AFAICT it is just the inheritence + const composure that is the problem.

It would be very nice if the __ didn't show up in autocomplete, since you aren't supposed to use them -- makes the generated code a lot more self documenting.

@jhugman
Copy link
Owner

jhugman commented Aug 30, 2024

Closing this in favour of #84.

@jhugman jhugman closed this Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants