denoland / denoland/std

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

Open
#7,172 1 comment 0 reactions 0 assignees View on GitHub
bug needs triage
Dominant language
TypeScript
Stars
3.6k
Forks
681
PR merge metrics
No merged PRs in 30d

Description

**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**

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

const arr: ReadonlyArray = [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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.