Skip to content

Commit

Permalink
fix: address TS2463 by layering optional param destructuring
Browse files Browse the repository at this point in the history
TS2463:
> A binding pattern parameter cannot be optional in an implementation signature.
  • Loading branch information
rvagg committed Aug 29, 2022
1 parent 8897781 commit af3a16c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/buffer-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class CarBufferWriter {
* @param {CID} root
* @param {{resize?:boolean}} [options]
*/
export const addRoot = (writer, root, { resize = false } = {}) => {
export const addRoot = (writer, root, options = {}) => {
const { resize = false } = options
const { bytes, headerSize, byteOffset, roots } = writer
writer.roots.push(root)
const size = headerLength(writer)
Expand Down Expand Up @@ -137,7 +138,8 @@ export const addBlock = (writer, { cid, bytes }) => {
* @param {object} [options]
* @param {boolean} [options.resize]
*/
export const close = (writer, { resize = false } = {}) => {
export const close = (writer, options = {}) => {
const { resize = false } = options
const { roots, bytes, byteOffset, headerSize } = writer

const headerBytes = CBOR.encode({ version: 1, roots })
Expand Down Expand Up @@ -266,15 +268,13 @@ export const estimateHeaderLength = (rootCount, rootByteLength = 36) =>
* @param {number} [options.headerSize]
* @returns {CarBufferWriter}
*/
export const createWriter = (
buffer,
{
export const createWriter = (buffer, options = {}) => {
const {
roots = [],
byteOffset = 0,
byteLength = buffer.byteLength,
headerSize = headerLength({ roots })
} = {}
) => {
} = options
const bytes = new Uint8Array(buffer, byteOffset, byteLength)

const writer = new CarBufferWriter(bytes, headerSize)
Expand Down

0 comments on commit af3a16c

Please sign in to comment.