You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Native node TestContext.assert is not typed correctly #59787
Assertions require every name in the call target to be declared with an explicit type annotation.(2775)
input.tsx(5, 15): 't' needs an explicit type annotation.
(property) TestContextAssert.strictEqual: (actual: unknown, expected: true, message?: string | Error) => asserts actual is true
Tests strict equality between the actual and expected parameters as determined by Object.is().
import assert from 'node:assert/strict';
assert.strictEqual(1, 2);
// AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
//
// 1 !== 2
🙂 Expected behavior
// Both cases should be treated the same way.
test('test', (t) => {
t.assert.strictEqual(true, true);
});
Every name in the call target needs to be declared with an explicit type annotation. TypeScript knows the types involved. Why does the parameter need to be explicit? I've read the issue and others like it but I failed to find the underlying reason why explicitly typed parameters are required or a workaround.
Using the native assertions doesn't help with the test plan when one is required. Can @types/node be updated so the first example works? If so, is that a ticket for DefinitelyTyped/DefinitelyTyped?
I appreciate any extra detail or dumbing-down of the information that you can provide.
This limitation is by design for performance reasons.
This library does not require your passed function to be an assertion function, or there are no identifiers without declared type (didn't check which one).
That would be a bad change. I'm sure it's intentional that it requires an assertion function.
I don't think this is a TypeScript issue per se, but it is weird that this works when node:assert is imported directly, but it doesn't when it's used off of node:test's TestContext object which, as far as I know, just re-exports node:assert.
Activity
MartinJohns commentedon Aug 28, 2024
This is working as intended per #32695. Assertions require every name in the call target to be declared with an explicit type annotation.
fidian commentedon Aug 28, 2024
I've got three questions.
Every name in the call target needs to be declared with an explicit type annotation. TypeScript knows the types involved. Why does the parameter need to be explicit? I've read the issue and others like it but I failed to find the underlying reason why explicitly typed parameters are required or a workaround.
Why does the native
assertpackage work?TypeScript Playground
@types/nodebe updated so the first example works? If so, is that a ticket for DefinitelyTyped/DefinitelyTyped?I appreciate any extra detail or dumbing-down of the information that you can provide.
MartinJohns commentedon Aug 28, 2024
typescript-bot commentedon Aug 31, 2024
This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
daviduzumeri commentedon Sep 4, 2024
I don't think this is a TypeScript issue per se, but it is weird that this works when
node:assertis imported directly, but it doesn't when it's used off ofnode:test'sTestContextobject which, as far as I know, just re-exportsnode:assert.daviduzumeri commentedon Sep 4, 2024
I expect this is an issue with
@types/nodeinstead and how it's typingTestContext's assert:Note when it's off of
node:assertit's a full function, but it's a lambda when it's onTestContext.resolve assertion type error