denoland / docs

Deno documentation, examples and API Reference. Powered by Lume.
https://docs.deno.com
MIT License
76 stars 157 forks source link

`BufferEncoding` global incorrectly documented #724

Open malthe opened 10 months ago

malthe commented 10 months ago

Version: Deno 1.38.5

type BufferEncoding =
    | 'ascii'
    | 'utf8'
    | 'utf-8'
    | 'utf16le'
    | 'ucs2'
    | 'ucs-2'
    | 'base64'
    | 'base64url'
    | 'latin1'
    | 'binary'
    | 'hex';
hallvors commented 2 months ago

Not sure if this is the right place to mention this, but the Deno docs here have two issues: https://docs.deno.com/api/node/buffer/~/BufferEncoding

  1. The suggested solution import { type BufferEncoding } from "node:buffer"; does not seem to work for me, trying to run a typescript file with this content says BufferEncoding is not exported from node:buffer
  2. I attempted to copy the definition from that page into my code instead, but the TS compiler complained about "utf-16le" which is in the docs definition but apparently not supported in node:buffer APIs.

If I should raise this somewhere else, I'm happy to do so.

dsherret commented 2 months ago

This is available on the NodeJS global when using the @types/node package (https://docs.deno.com/runtime/manual/node/npm_specifiers/#including-node-types).

function example(encoding: NodeJS.BufferEncoding) {
}

I moved this issue to the docs repo becacuse it incorrectly says to import it from the node:buffer module as @hallvors pointed out.

james-pre commented 1 week ago

The docs still reference importing from node:buffer, which still doesn't work.