Skip to content

[@std/cbor] [types] Cbor encoding types should allow readonly arrays #7172

@Jamesernator

Description

@Jamesernator

Describe the bug

Cbor.CBORType/CborStreamInput/etc doesn't allow ReadonlyArray. These should be allowed to encoders as CBOR encoding methods don't mutate their inputs.

Steps to Reproduce

import * as CBOR from "jsr:@std/cbor";

const arr: ReadonlyArray<number> = [1, 2, 3];
// Argument of type 'readonly number[]' is not assignable to parameter of type 'CborType'.
CBOR.encodeCbor(arr);

const encoder = new CBOR.CborSequenceEncoderStream(); 
const writer = encoder.getWriter();
// Argument of type 'readonly number[]' is not assignable to parameter of type 'CborStreamInput'.
writer.write(arr);

Expected behavior

These types should be accepted.

Actual behavior

We get a typescript typing error.

Environment

  • OS: Ubuntu 26.04
  • deno version: 2.8.1
  • std version: 0.1.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions