Skip to content

In JS, expando properties of a function are always treated as static methods #25906

Closed
@sandersn

Description

@sandersn
var assert = function() { };
assert.AssertionError = function (actual, expect) {
    this.name = 'AssertionError';
    this.actual = actual;
    this.expected = expect;
}

Expected behavior:
No errors, and this: AssertionError, and assert.AssertionError is a constructor function.

Actual behavior:
this: typeof assert, which is a function, so that, for example this.name tries to overwrite the built-in Function.name. Basically, assert.AssertionError behaves like a static method of assert instead of a static property that is a constructor function.

Note that usage of assert.AssertionError works as desired: you can say new assert.AssertionError().actual.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptcheckJsRelates to checking JavaScript using TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions