Closed
Description
Greetings folks! 👋
I'm getting a type error I can't explain. I have some code like this:
function doStuff(foo: string|Buffer) {
return Buffer.from(foo);
}
This gives me the compilation error:
Argument of type 'string | Buffer' is not assignable to parameter of type 'string'. Type 'Buffer' is not assignable to type 'string'.
This is weird, because Buffer.from
can accept a string or a Buffer. The d.ts for node.js appears to check out:
/**
* Copies the passed {buffer} data onto a new Buffer instance.
*/
from(buffer: Buffer): Buffer;
/**
* Creates a new Buffer containing the given JavaScript string {str}.
* If provided, the {encoding} parameter identifies the character encoding.
* If not provided, {encoding} defaults to 'utf8'.
*/
from(str: string, encoding?: string): Buffer;
This kinda feels like a bug. Am I missing something? Thanks!
cc @ofrobots