Skip to content

Commit c39cb48

Browse files
feat: remove ts-expose-internals (#1968)
1 parent 49df2de commit c39cb48

File tree

7 files changed

+15
-18
lines changed

7 files changed

+15
-18
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"@types/jest": "^29.5.12",
7272
"@types/node": "^20.12.7",
7373
"@types/normalize-path": "^3.0.2",
74-
"@types/ts-expose-internals": "npm:ts-expose-internals@^5.4.5",
7574
"ajv": "^8.12.0",
7675
"ajv-formats": "^3.0.1",
7776
"auto": "^11.1.6",

src/NodeParser/FunctionNodeParser.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import ts from "typescript";
2-
import { SubNodeParser } from "../SubNodeParser.js";
3-
import { BaseType } from "../Type/BaseType.js";
2+
import type { SubNodeParser } from "../SubNodeParser.js";
3+
import type { BaseType } from "../Type/BaseType.js";
44
import { FunctionType } from "../Type/FunctionType.js";
5-
import { FunctionOptions } from "../Config.js";
5+
import type { FunctionOptions } from "../Config.js";
66
import { NeverType } from "../Type/NeverType.js";
77
import { DefinitionType } from "../Type/DefinitionType.js";
8-
import { Context, NodeParser } from "../NodeParser.js";
8+
import type { Context, NodeParser } from "../NodeParser.js";
99
import { ObjectProperty, ObjectType } from "../Type/ObjectType.js";
1010
import { getKey } from "../Utils/nodeKey.js";
1111

@@ -15,14 +15,11 @@ export class FunctionNodeParser implements SubNodeParser {
1515
protected functions: FunctionOptions,
1616
) {}
1717

18-
public supportsNode(node: ts.TypeNode): boolean {
18+
public supportsNode(node: ts.Node): boolean {
1919
return (
2020
node.kind === ts.SyntaxKind.FunctionType ||
21-
// @ts-expect-error internals type bug
2221
node.kind === ts.SyntaxKind.FunctionExpression ||
23-
// @ts-expect-error internals type bug
2422
node.kind === ts.SyntaxKind.ArrowFunction ||
25-
// @ts-expect-error internals type bug
2623
node.kind === ts.SyntaxKind.FunctionDeclaration
2724
);
2825
}

src/NodeParser/PromiseNodeParser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class PromiseNodeParser implements SubNodeParser {
3232

3333
const type = this.typeChecker.getTypeAtLocation(node);
3434

35+
//@ts-expect-error - internal typescript API
3536
const awaitedType = this.typeChecker.getAwaitedType(type);
3637

3738
// ignores non awaitable types
@@ -60,7 +61,8 @@ export class PromiseNodeParser implements SubNodeParser {
6061
context: Context,
6162
): BaseType {
6263
const type = this.typeChecker.getTypeAtLocation(node);
63-
const awaitedType = this.typeChecker.getAwaitedType(type)!; // supportsNode ensures this
64+
//@ts-expect-error - internal typescript API
65+
const awaitedType = this.typeChecker.getAwaitedType(type);
6466
const awaitedNode = this.typeChecker.typeToTypeNode(awaitedType, undefined, ts.NodeBuilderFlags.IgnoreErrors);
6567

6668
if (!awaitedNode) {

src/NodeParser/TypeReferenceNodeParser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AnyType } from "../Type/AnyType.js";
66
import { ArrayType } from "../Type/ArrayType.js";
77
import type { BaseType } from "../Type/BaseType.js";
88
import { StringType } from "../Type/StringType.js";
9+
import { symbolAtNode } from "../Utils/symbolAtNode.js";
910

1011
const invalidTypes: Record<number, boolean> = {
1112
[ts.SyntaxKind.ModuleDeclaration]: true,
@@ -28,7 +29,7 @@ export class TypeReferenceNodeParser implements SubNodeParser {
2829
// When the node doesn't have a valid source file, its position is -1, so we can't
2930
// search for a symbol based on its location. In that case, the ts.factory defines a symbol
3031
// property on the node itself.
31-
(node.typeName as unknown as ts.Type).symbol;
32+
symbolAtNode(node.typeName)!;
3233

3334
if (typeSymbol.flags & ts.SymbolFlags.Alias) {
3435
const aliasedSymbol = this.typeChecker.getAliasedSymbol(typeSymbol);

src/SchemaGenerator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { TypeFormatter } from "./TypeFormatter.js";
1010
import type { StringMap } from "./Utils/StringMap.js";
1111
import { hasJsDocTag } from "./Utils/hasJsDocTag.js";
1212
import { removeUnreachable } from "./Utils/removeUnreachable.js";
13+
import { symbolAtNode } from "./Utils/symbolAtNode.js";
1314

1415
export class SchemaGenerator {
1516
public constructor(
@@ -262,6 +263,7 @@ export class SchemaGenerator {
262263
return false;
263264
}
264265

266+
//@ts-expect-error - internal typescript API
265267
return !!node.localSymbol?.exportSymbol;
266268
}
267269

@@ -270,6 +272,6 @@ export class SchemaGenerator {
270272
}
271273

272274
protected getFullName(node: ts.Declaration, typeChecker: ts.TypeChecker): string {
273-
return typeChecker.getFullyQualifiedName(node.symbol).replace(/".*"\./, "");
275+
return typeChecker.getFullyQualifiedName(symbolAtNode(node)!).replace(/".*"\./, "");
274276
}
275277
}

src/Utils/symbolAtNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type ts from "typescript";
22

33
export function symbolAtNode(node: ts.Node): ts.Symbol | undefined {
4-
return (node as ts.Declaration).symbol;
4+
//@ts-expect-error - internal typescript API
5+
return node.symbol;
56
}

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,11 +1976,6 @@
19761976
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8"
19771977
integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==
19781978

1979-
"@types/ts-expose-internals@npm:ts-expose-internals@^5.4.5":
1980-
version "5.4.5"
1981-
resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-5.4.5.tgz#94da2b665627135ad1281d98af3ccb08cb4c1950"
1982-
integrity sha512-0HfRwjgSIOyuDlHzkFedMWU4aHWq9pu4MUKHgH75U+L76wCAtK5WB0rc/dAIhulMRcPUlcKONeiiR5Sxy/7XcA==
1983-
19841979
"@types/yargs-parser@*":
19851980
version "21.0.3"
19861981
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.3.tgz#815e30b786d2e8f0dcd85fd5bcf5e1a04d008f15"

0 commit comments

Comments
 (0)