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

Error importing SCHEMA_TYPES enum when using index.d.ts. #292

Open
bloodgang94 opened this issue May 3, 2024 · 3 comments
Open

Error importing SCHEMA_TYPES enum when using index.d.ts. #292

bloodgang94 opened this issue May 3, 2024 · 3 comments
Assignees
Labels
❓ Question Further information is requested

Comments

@bloodgang94
Copy link

Hello! My project is on typescript. I moved index.d.ts to my project.

When importing SCHEMA_TYPES I get the error TypeError: Cannot read property 'SCHEMA_TYPE_AVRO' of undefined

Example

import { SCHEMA_TYPES, SchemaRegistry } from 'k6/x/kafka'
....
console.log(SCHEMA_TYPES.SCHEMA_TYPE_AVRO)
declare module 'k6/x/kafka' {
  /**
   * @packageDocumentation
   * xk6-kafka is a k6 extension to load test Apache Kafka
   */

  /**
   * @module k6/x/kafka
   * @description
   * The xk6-kafka project is a k6 extension that enables k6 users to load test Apache Kafka using a producer and possibly a consumer for debugging.
   * This documentation refers to the development version of the xk6-kafka project, which means the latest changes on `main` branch and might not be released yet, as explained in [the release process](https://github.com/mostafa/xk6-kafka#the-release-process).
   * @see {@link https://github.com/mostafa/xk6-kafka}
   */

  /** Compression codecs for compressing messages when producing to a topic or reading from it. */
  export enum COMPRESSION_CODECS {
.....

tsconfig

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "load/*": ["./*"]
    },
    "target": "es2017",                        
    "module": "commonjs",                     
    "lib": [                                
      "esnext",
      "dom"
    ],
  
    "declaration": true,                  
    "declarationDir": "./dist/types",
    "sourceMap": true,                      
    "outDir": "./dist",                     
    "strict": true,                          
    "moduleResolution": "node",               
    "typeRoots": [                           
      "node_modules/@types",
      "./types"
    ],
    "esModuleInterop": true,                  
    "experimentalDecorators": true,       
    "emitDecoratorMetadata": true           
  },

  "exclude": [
    "node_modules"
  ],
  "include": [
    "src",
  ],

}

I found a similar
problem

If you change it to constant then there is no error. Do I understand correctly that index.d.ts is not relevant?
image

@mostafa
Copy link
Owner

mostafa commented May 3, 2024

Hey @bloodgang94,

There is no such symbol named SCHEMA_TYPES and these are the schema types you can import into your code.

xk6-kafka/module.go

Lines 210 to 215 in 1d8e9ef

// Schema types
mustAddProp("SCHEMA_TYPE_STRING", String)
mustAddProp("SCHEMA_TYPE_BYTES", Bytes)
mustAddProp("SCHEMA_TYPE_AVRO", srclient.Avro)
mustAddProp("SCHEMA_TYPE_JSON", srclient.Json)
mustAddProp("SCHEMA_TYPE_PROTOBUF", srclient.Protobuf)

As for the index.d.ts file, I tried to keep it as close to the exported parameters as I can and it is still relevant, AFAIK. I used enums to be able to reference them in other types, but they are actually constants, so you'd better import the actual constant.

@mostafa mostafa added the ❓ Question Further information is requested label May 3, 2024
@mostafa mostafa self-assigned this May 3, 2024
@bloodgang94
Copy link
Author

@mostafa , how did you think about fixing index.d.ts? I can help you with this by making a merge request. It would also be nice to publish it there https://github.com/DefinitelyTyped/DefinitelyTyped

@mostafa
Copy link
Owner

mostafa commented May 7, 2024

@bloodgang94 Go for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ Question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants