Skip to content

Commit 2f025b7

Browse files
committed
fix(nodejstypes): node globals types are now excluded when analyzing type properties
Node 16.6 introduced Array.at -> https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V16.md#2021-07-29-version-1660-current-bethgriggs As a consequence of that @types/node 16.6 introduced the types for that DefinitelyTyped/DefinitelyTyped@dca7357#diff-2696281f8832b1227bb41483a7525a8ccd9399bb4b1704f69c8c54bb1346d8edR80
1 parent 61c9fbc commit 2f025b7

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@types/jasmine": "^4.0.3",
6464
"@types/lodash-es": "^4.17.6",
6565
"@types/micromatch": "^4.0.2",
66-
"@types/node": "^16.4.13",
66+
"@types/node": "^16.6.0",
6767
"@typescript-eslint/eslint-plugin": "^5.21.0",
6868
"@typescript-eslint/parser": "^5.21.0",
6969
"all-contributors-cli": "6.20.0",

src/transformer/descriptor/mock/mockProperties.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Scope } from '../../scope/scope';
33
import { core } from '../../core/core';
44
import { GetDescriptor } from '../descriptor';
55
import { IsTypescriptType } from '../tsLibs/typecriptLibs';
6+
import { IsNodeType } from '../nodeTypes/nodeTypes';
67
import { GetMockCall } from './mockCall';
78
import {
89
GetMockPropertiesAssignments,
@@ -47,7 +48,12 @@ export function GetMockPropertiesFromDeclarations(
4748
const modifiers: ts.ModifiersArray | undefined = member.modifiers;
4849

4950
if (IsTypescriptType(member)) {
50-
// This is a current workaround to safe fail extends of TypescriptLibs
51+
// Workaround to remove any properties coming from typescript/lib
52+
return false;
53+
}
54+
55+
if (IsNodeType(member)) {
56+
// Workaround to remove any properties coming from @types/node globals
5157
return false;
5258
}
5359

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type * as ts from 'typescript';
2+
3+
const NodeTypesGlobalFile: string = 'node_modules/@types/node/globals.d.ts';
4+
5+
export function IsNodeType(node: ts.Node): boolean {
6+
const nodeFile: ts.SourceFile = node.getSourceFile();
7+
8+
if (nodeFile) {
9+
const fileName: string = nodeFile.fileName;
10+
return fileName.includes(NodeTypesGlobalFile);
11+
}
12+
13+
return false;
14+
}

0 commit comments

Comments
 (0)