Skip to content

Missing standard Function prototype (e.g. chalk.apply is not a function) #388

@LinusU

Description

@LinusU

I was logging a lot of things to stderr in my TypeScript project, so I wanted to create a neat wrapper for this:

function log (text: TemplateStringsArray, ...placeholders: unknown[]): void {
  console.error(chalk.stderr(text, ...placeholders))
}

Unfortunately, this yielded the following error:

TypeError: chalk.apply is not a function
    at log (/foo/bar.ts:2:22)

I hadn't yet setup a tsconfig, so my project was targeting ES5. This meant that the ...placeholders call was converted to use .apply, which is assumed to exist on every function.

However, since chalk changes the prototype of the function, there is no longer any apply, call or other things from the Function prototype.

I think that this could be easily resolved by adding in apply, call, etc. manually. But I wanted to open this to get some feedback first.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions