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

Type error when updating file-asset-apis #1047

Open
busma13 opened this issue Aug 21, 2024 · 2 comments
Open

Type error when updating file-asset-apis #1047

busma13 opened this issue Aug 21, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@busma13
Copy link
Contributor

busma13 commented Aug 21, 2024

When updating file-asset-apis to v 1.0.0 in teraslice/terafoundation there are 2 type errors:

packages/teraslice/src/lib/storage/backends/s3_store.ts:79:53 - error TS2339: Property 'BucketAlreadyExists' does not exist on type 'typeof import("/Users/<username>/WORKSPACE/teraslice/node_modules/@terascope/file-asset-apis/dist/src/s3/client-types/client-response")'.

79                 if (err instanceof S3ClientResponse.BucketAlreadyExists) {
                                                       ~~~~~~~~~~~~~~~~~~~

packages/teraslice/src/lib/storage/backends/s3_store.ts:128:49 - error TS2339: Property 'NoSuchKey' does not exist on type 'typeof import("/Users/<username>/WORKSPACE/teraslice/node_modules/@terascope/file-asset-apis/dist/src/s3/client-types/client-response")'.

128             if (err instanceof S3ClientResponse.NoSuchKey) {

I can navigate to client-response.d.ts and the types are present.

@busma13 busma13 added the bug Something isn't working label Aug 21, 2024
@sotojn sotojn self-assigned this Aug 23, 2024
@sotojn
Copy link
Contributor

sotojn commented Aug 23, 2024

instanceof works by checking the object's prototype chain against the prototype of the specified constructor function. This means it needs access to the actual constructor function of the class.

The issue is that the last update to v1.0.0 in file-asset-apis changed these exports to just export the type instead of the actual class.

Another thing I learned about types is that they do not exist at runtime, so they are not properties of the imported object. Meaning you can only use types for checking and defining structure but cannot access them as actual values or properties at runtime. The way we're using them here is trying to access the imported object S3ClientResponse then looking in the object for a NoSuchKey type property, but again the don't exist at runtime. Hence the error saying the property doesn't exist.

Solution: Update file-asset-apis to export the full classes so we can use them in teraslice. This could be a separate export called client-classes that we would use instead. Or we could just rename client-types to client-classes and have the dev using file-asset-apis to import the types using import types

@jsnoble
Copy link
Member

jsnoble commented Aug 23, 2024

Yes, types only exist for type checking and do not exist in runtime unless its an enum, that translates to an actual value. If you need the actual things, then all you need to do is change export type { to export {.

I agree with the notion of changing the name of the top level directory as client-types make you think they are all types. Maybe just change it to native-client-helpers or the like, make sure to change client-params as well as client-repsonse to remove the type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants