kriszyp / cbor-x

Ultra-fast CBOR encoder/decoder with extensions for records and structural cloning
MIT License
265 stars 33 forks source link

TypeScript reporting issues in shipped `index.d.ts` file #37

Open jloleysens opened 2 years ago

jloleysens commented 2 years ago

Hello!

When building a project I am seeing the following compiler issues from TS:

node_modules/cbor-x/index.d.ts:1:58 - error TS2305: Module '"./decode.js"' has no exported member 'clearSource'.

1 export { Decoder, decode, addExtension, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './decode.js'
                                                           ~~~~~~~~~~~

node_modules/cbor-x/index.d.ts:7:24 - error TS2304: Cannot find name 'Options'.

7  constructor(options?: Options | { highWaterMark: number, emitClose: boolean, allowHalfOpen: boolean })
                         ~~~~~~~

node_modules/cbor-x/index.d.ts:10:24 - error TS2304: Cannot find name 'Options'.

10  constructor(options?: Options | { highWaterMark: number, emitClose: boolean, allowHalfOpen: boolean })
                          ~~~~~~~

Looking at the file, it does look like these issues are accurate since there is no Options and it seems as though decode.d.ts needs to be updated to declare and export the clearSource function.

kriszyp commented 2 years ago

Publish a fix for this and #36 in v1.3.2. Let me know if you see any issues with it. Thank you for the reports!

shubhamvrkr commented 2 years ago

Hi @kriszyp , i am getting error in typescript whenever i am using keyMap option in Encoder class as shown in the example. KeyMaps for Senml: https://www.npmjs.com/package/cbor-x let senmlCbor = new Encoder({ keyMap: senmlKeys }). Looks like the options in decode constructor doesn't have keyMap option. Ref: https://github.com/kriszyp/cbor-x/blob/master/decode.d.ts#L8. Kindly let me know if i am missing something here.

kriszyp commented 2 years ago

@shubhamvrkr published keyMap typing in v1.3.3.

shubhamvrkr commented 2 years ago

@kriszyp Is there an option/plan to enable validity of the items during cbor decoding. https://www.ietf.org/archive/id/draft-ietf-cbor-7049bis-16.html#name-validity-of-items