-
Notifications
You must be signed in to change notification settings - Fork 30.5k
[@types/node] use assertion guards in assert module #42786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rbuckton
merged 6 commits into
DefinitelyTyped:master
from
G-Rath:add-asserts-to-node-types
Apr 22, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
805046c
feat(node): Add support for TypeScript 3.7 assertion functions
G-Rath d0123da
fix(adone): use `any` for type of `assert` module
G-Rath 93f43b0
chore(node): rename `internal` namespace to `assert`
G-Rath 9fe91d2
chore(node): adjust `typesVersions` order
G-Rath 2a60af2
chore(node): clean up `typesVersions` ranges
G-Rath c6c2a4c
Revert "chore(node): clean up `typesVersions` ranges"
G-Rath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // NOTE: These definitions support NodeJS and TypeScript 3.2. | ||
|
|
||
| // NOTE: TypeScript version-specific augmentations can be found in the following paths: | ||
| // - ~/base.d.ts - Shared definitions common to all TypeScript versions | ||
| // - ~/index.d.ts - Definitions specific to TypeScript 2.1 | ||
| // - ~/ts3.2/base.d.ts - Definitions specific to TypeScript 3.2 | ||
| // - ~/ts3.2/index.d.ts - Definitions specific to TypeScript 3.2 with assert pulled in | ||
|
|
||
| // Reference required types from the default lib: | ||
| /// <reference lib="es2018" /> | ||
| /// <reference lib="esnext.asynciterable" /> | ||
| /// <reference lib="esnext.intl" /> | ||
| /// <reference lib="esnext.bigint" /> | ||
|
|
||
| // Base definitions for all NodeJS modules that are not specific to any version of TypeScript: | ||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../base.d.ts" /> | ||
|
|
||
| // TypeScript 3.2-specific augmentations: | ||
| /// <reference path="fs.d.ts" /> | ||
| /// <reference path="util.d.ts" /> | ||
| /// <reference path="globals.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,8 @@ | ||
| // NOTE: These definitions support NodeJS and TypeScript 3.2. | ||
| // This is requried to enable typing assert in ts3.7 without causing errors | ||
| // Typically type modifiations should be made in base.d.ts instead of here | ||
|
|
||
| // Reference required types from the default lib: | ||
| /// <reference lib="es2018" /> | ||
| /// <reference lib="esnext.asynciterable" /> | ||
| /// <reference lib="esnext.intl" /> | ||
| /// <reference lib="esnext.bigint" /> | ||
| /// <reference path="base.d.ts" /> | ||
|
|
||
| // Base definitions for all NodeJS modules that are not specific to any version of TypeScript: | ||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../base.d.ts" /> | ||
|
|
||
| // TypeScript 3.2-specific augmentations: | ||
| /// <reference path="fs.d.ts" /> | ||
| /// <reference path="util.d.ts" /> | ||
| /// <reference path="globals.d.ts" /> | ||
| /// <reference path="../assert.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // NOTE: These definitions support NodeJS and TypeScript 3.5. | ||
|
|
||
| // NOTE: TypeScript version-specific augmentations can be found in the following paths: | ||
| // - ~/base.d.ts - Shared definitions common to all TypeScript versions | ||
| // - ~/index.d.ts - Definitions specific to TypeScript 2.1 | ||
| // - ~/ts3.5/base.d.ts - Definitions specific to TypeScript 3.5 | ||
| // - ~/ts3.5/index.d.ts - Definitions specific to TypeScript 3.5 with assert pulled in | ||
|
|
||
| // Reference required types from the default lib: | ||
| /// <reference lib="es2018" /> | ||
| /// <reference lib="esnext.asynciterable" /> | ||
| /// <reference lib="esnext.intl" /> | ||
| /// <reference lib="esnext.bigint" /> | ||
|
|
||
| // Base definitions for all NodeJS modules that are not specific to any version of TypeScript: | ||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../ts3.2/base.d.ts" /> | ||
|
|
||
| // TypeScript 3.5-specific augmentations: | ||
| /// <reference path="wasi.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,8 @@ | ||
| // NOTE: These definitions support NodeJS and TypeScript 3.5. | ||
| // This is requried to enable typing assert in ts3.7 without causing errors | ||
| // Typically type modifiations should be made in base.d.ts instead of here | ||
|
|
||
| // Reference required types from the default lib: | ||
| /// <reference lib="es2018" /> | ||
| /// <reference lib="esnext.asynciterable" /> | ||
| /// <reference lib="esnext.intl" /> | ||
| /// <reference lib="esnext.bigint" /> | ||
| /// <reference path="base.d.ts" /> | ||
|
|
||
| // Base definitions for all NodeJS modules that are not specific to any version of TypeScript: | ||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../ts3.2/index.d.ts" /> | ||
|
|
||
| // TypeScript 3.5-specific augmentations: | ||
| /// <reference path="wasi.d.ts" /> | ||
| /// <reference path="../assert.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| declare module "assert" { | ||
| function assert(value: any, message?: string | Error): asserts value; | ||
| namespace assert { | ||
| class AssertionError implements Error { | ||
| name: string; | ||
| message: string; | ||
| actual: any; | ||
| expected: any; | ||
| operator: string; | ||
| generatedMessage: boolean; | ||
| code: 'ERR_ASSERTION'; | ||
|
|
||
| constructor(options?: { | ||
| message?: string; actual?: any; expected?: any; | ||
| operator?: string; stackStartFn?: Function | ||
| }); | ||
| } | ||
|
|
||
| type AssertPredicate = RegExp | (new() => object) | ((thrown: any) => boolean) | object | Error; | ||
|
|
||
| function fail(message?: string | Error): never; | ||
| /** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */ | ||
| function fail(actual: any, expected: any, message?: string | Error, operator?: string, stackStartFn?: Function): never; | ||
| function ok(value: any, message?: string | Error): asserts value; | ||
| /** @deprecated since v9.9.0 - use strictEqual() instead. */ | ||
| function equal(actual: any, expected: any, message?: string | Error): void; | ||
| /** @deprecated since v9.9.0 - use notStrictEqual() instead. */ | ||
| function notEqual(actual: any, expected: any, message?: string | Error): void; | ||
| /** @deprecated since v9.9.0 - use deepStrictEqual() instead. */ | ||
| function deepEqual(actual: any, expected: any, message?: string | Error): void; | ||
| /** @deprecated since v9.9.0 - use notDeepStrictEqual() instead. */ | ||
| function notDeepEqual(actual: any, expected: any, message?: string | Error): void; | ||
| function strictEqual<T>(actual: any, expected: T, message?: string | Error): asserts actual is T; | ||
| function notStrictEqual(actual: any, expected: any, message?: string | Error): void; | ||
| function deepStrictEqual<T>(actual: any, expected: T, message?: string | Error): asserts actual is T; | ||
| function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void; | ||
|
|
||
| function throws(block: () => any, message?: string | Error): void; | ||
| function throws(block: () => any, error: AssertPredicate, message?: string | Error): void; | ||
| function doesNotThrow(block: () => any, message?: string | Error): void; | ||
| function doesNotThrow(block: () => any, error: RegExp | Function, message?: string | Error): void; | ||
|
|
||
| function ifError(value: any): asserts value is null | undefined; | ||
|
|
||
| function rejects(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>; | ||
| function rejects(block: (() => Promise<any>) | Promise<any>, error: AssertPredicate, message?: string | Error): Promise<void>; | ||
| function doesNotReject(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>; | ||
| function doesNotReject(block: (() => Promise<any>) | Promise<any>, error: RegExp | Function, message?: string | Error): Promise<void>; | ||
|
|
||
| function match(value: string, regExp: RegExp, message?: string | Error): void; | ||
| function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void; | ||
|
|
||
| const strict: typeof assert; | ||
| } | ||
|
|
||
| export = assert; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // NOTE: These definitions support NodeJS and TypeScript 3.7. | ||
|
|
||
| // NOTE: TypeScript version-specific augmentations can be found in the following paths: | ||
| // - ~/base.d.ts - Shared definitions common to all TypeScript versions | ||
| // - ~/index.d.ts - Definitions specific to TypeScript 2.1 | ||
| // - ~/ts3.7/base.d.ts - Definitions specific to TypeScript 3.7 | ||
| // - ~/ts3.7/index.d.ts - Definitions specific to TypeScript 3.7 with assert pulled in | ||
|
|
||
| // Reference required types from the default lib: | ||
| /// <reference lib="es2018" /> | ||
| /// <reference lib="esnext.asynciterable" /> | ||
| /// <reference lib="esnext.intl" /> | ||
| /// <reference lib="esnext.bigint" /> | ||
|
|
||
| // Base definitions for all NodeJS modules that are not specific to any version of TypeScript: | ||
| // tslint:disable-next-line:no-bad-reference | ||
| /// <reference path="../ts3.5/base.d.ts" /> | ||
|
|
||
| // TypeScript 3.7-specific augmentations: | ||
| /// <reference path="assert.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // NOTE: These definitions support NodeJS and TypeScript 3.7. | ||
| // This isn't strictly needed since 3.7 has the assert module, but this way we're consistent. | ||
| // Typically type modificatons should be made in base.d.ts instead of here | ||
|
|
||
| /// <reference path="base.d.ts" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import * as assert from 'assert'; | ||
|
|
||
| assert(true, "it's working"); | ||
|
|
||
| assert.ok(true, 'inner functions work as well'); | ||
|
|
||
| assert.throws(() => {}); | ||
| assert.throws(() => {}, /Regex test/); | ||
| assert.throws( | ||
| () => {}, | ||
| () => {}, | ||
| 'works wonderfully', | ||
| ); | ||
|
|
||
| assert['fail'](true, true, 'works like a charm'); | ||
|
|
||
| { | ||
| const a = null as any; | ||
| assert.ifError(a); | ||
| a; // $ExpectType null | undefined | ||
| } | ||
|
|
||
| { | ||
| const a = true as boolean; | ||
| assert(a); | ||
| a; // $ExpectType true | ||
| } | ||
|
|
||
| { | ||
| // tslint:disable-next-line: no-null-undefined-union | ||
| const a = 13 as number | null | undefined; | ||
| assert(a); | ||
| a; // $ExpectType number | ||
| } | ||
|
|
||
| { | ||
| const a = true as boolean; | ||
| assert.ok(a); | ||
| a; // $ExpectType true | ||
| } | ||
|
|
||
| { | ||
| // tslint:disable-next-line: no-null-undefined-union | ||
| const a = 13 as number | null | undefined; | ||
| assert.ok(a); | ||
| a; // $ExpectType number | ||
| } | ||
|
|
||
| { | ||
| const a = 'test' as any; | ||
| assert.strictEqual(a, 'test'); | ||
| a; // $ExpectType string | ||
| } | ||
|
|
||
| { | ||
| const a = { b: 2 } as any; | ||
| assert.deepStrictEqual(a, { b: 2 }); | ||
| a; // $ExpectType { b: number; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "files": [ | ||
| "index.d.ts", | ||
| "node-tests.ts" | ||
| ], | ||
| "compilerOptions": { | ||
| "module": "commonjs", | ||
| "target": "esnext", | ||
| "lib": [ | ||
| "es6", | ||
| "dom" | ||
| ], | ||
| "noImplicitAny": true, | ||
| "noImplicitThis": true, | ||
| "strictNullChecks": true, | ||
| "strictFunctionTypes": true, | ||
| "baseUrl": "../../", | ||
| "typeRoots": [ | ||
| "../../" | ||
| ], | ||
| "types": [], | ||
| "noEmit": true, | ||
| "forceConsistentCasingInFileNames": true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "dtslint/dt.json", | ||
| "rules": { | ||
| "ban-types": false, | ||
| "unified-signatures": false, | ||
| "no-empty-interface": false, | ||
| "no-single-declare-module": false, | ||
| "strict-export-declare-modifiers": false // http2 needs this | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only dependent for this package on npm is bloater, which just depends on the first 1000 dependencies on npm, and is an attempt to just publish a really large package by the looks of it.
The
adonenpm package itself is deprecated, and the github project, while recently updated ~20 days ago, doesn't seem to have thestdnamespace anymore.Of the two maintainers of these types, one no longer exists on github, and the other has no active contributions.
I believe it's acceptable in this case to slightly weaken the types of a single package that doesn't appear to be used anymore, vs not having assertion guards in
@types/node.Happy to break this out into another PR if needed.