Definitelytyped: @types/node Use Typescript 3.7 asserts syntax for node's assert function

Created on 15 Nov 2019  路  7Comments  路  Source: DefinitelyTyped/DefinitelyTyped

About the asserts feature:
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
https://github.com/microsoft/TypeScript/pull/32695

Basically I would like to change:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/9f57df89f30bacee1d46dfbf40a08132b4b059ef/types/node/assert.d.ts#L2

into this:

function internal(value: any, message?: string | Error): asserts value;

Since this TypeScript feature has been released only recently, how should this best be added to the types without breaking compilation on older TypeScript versions?

cc @Flarna @rbuckton @jstewmon (This is obviously not the complete list of authors because I didn't want to ping too many people. While browsing the source these names came up. Please ping anyone who you think should be involved in the discussion)

Most helpful comment

For @types/assert it seems to be already done, see #41179. They made a ts3.7 sub-folder.

All 7 comments

Technically it's possible by adding a ts3.7 folder and add the modified asserts.d.ts file there. Maybe it's needed to copy also files from 3.2 folder perferred is to just include them instead of copy.
There are a few 3.2 extensions for APIs supporting BigInt.

But be aware that this adds mainainance effort as once assert is split up it has to be maintained in both files. For assert this is maybe not that bad because the APIs is not changing frequently.

Maybe we can bump up the ts3.2 folder to 3.7?
@RyanCavanaugh in this issue you mentioned you have telemetry, is this telemetry openly accessible?
It would be incredibly valuable for developers to be able to use this data in order to make support decisions for their packages.

This was somewhat recently done for invariant.

Type guards for built-in node assert functions would be really useful to have. Are they are plans to implement this?

Thanks.

For @types/assert it seems to be already done, see #41179. They made a ts3.7 sub-folder.

I've made a strawman PR to get the ball rolling :)

Just an FYI, this has been shipped, but currently won't work because the typesVersions property is being sorted before publishing, meaning that the new ts3.7 types are never actually applied.

This is being tracked by #44117

Was this page helpful?
0 / 5 - 0 ratings

Related issues

variousauthors picture variousauthors  路  3Comments

jbreckmckye picture jbreckmckye  路  3Comments

lilling picture lilling  路  3Comments

ArtemZag picture ArtemZag  路  3Comments

JWT
svipas picture svipas  路  3Comments