Skip to content
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

fix: remove ts-expose-types temporarily #1968

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"@types/jest": "^29.5.12",
"@types/node": "^20.12.7",
"@types/normalize-path": "^3.0.2",
"@types/ts-expose-internals": "npm:ts-expose-internals@^5.4.5",
"ajv": "^8.12.0",
"ajv-formats": "^3.0.1",
"auto": "^11.1.6",
Expand Down
13 changes: 5 additions & 8 deletions src/NodeParser/FunctionNodeParser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ts from "typescript";
import { SubNodeParser } from "../SubNodeParser.js";
import { BaseType } from "../Type/BaseType.js";
import type { SubNodeParser } from "../SubNodeParser.js";
import type { BaseType } from "../Type/BaseType.js";
import { FunctionType } from "../Type/FunctionType.js";
import { FunctionOptions } from "../Config.js";
import type { FunctionOptions } from "../Config.js";
import { NeverType } from "../Type/NeverType.js";
import { DefinitionType } from "../Type/DefinitionType.js";
import { Context, NodeParser } from "../NodeParser.js";
import type { Context, NodeParser } from "../NodeParser.js";
import { ObjectProperty, ObjectType } from "../Type/ObjectType.js";
import { getKey } from "../Utils/nodeKey.js";

Expand All @@ -15,14 +15,11 @@ export class FunctionNodeParser implements SubNodeParser {
protected functions: FunctionOptions,
) {}

public supportsNode(node: ts.TypeNode): boolean {
public supportsNode(node: ts.Node): boolean {
return (
node.kind === ts.SyntaxKind.FunctionType ||
// @ts-expect-error internals type bug
node.kind === ts.SyntaxKind.FunctionExpression ||
// @ts-expect-error internals type bug
node.kind === ts.SyntaxKind.ArrowFunction ||
// @ts-expect-error internals type bug
node.kind === ts.SyntaxKind.FunctionDeclaration
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/NodeParser/PromiseNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class PromiseNodeParser implements SubNodeParser {

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

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

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

if (!awaitedNode) {
Expand Down
3 changes: 2 additions & 1 deletion src/NodeParser/TypeReferenceNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AnyType } from "../Type/AnyType.js";
import { ArrayType } from "../Type/ArrayType.js";
import type { BaseType } from "../Type/BaseType.js";
import { StringType } from "../Type/StringType.js";
import { symbolAtNode } from "../Utils/symbolAtNode.js";

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

if (typeSymbol.flags & ts.SymbolFlags.Alias) {
const aliasedSymbol = this.typeChecker.getAliasedSymbol(typeSymbol);
Expand Down
4 changes: 3 additions & 1 deletion src/SchemaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { TypeFormatter } from "./TypeFormatter.js";
import type { StringMap } from "./Utils/StringMap.js";
import { hasJsDocTag } from "./Utils/hasJsDocTag.js";
import { removeUnreachable } from "./Utils/removeUnreachable.js";
import { symbolAtNode } from "./Utils/symbolAtNode.js";

export class SchemaGenerator {
public constructor(
Expand Down Expand Up @@ -262,6 +263,7 @@ export class SchemaGenerator {
return false;
}

//@ts-expect-error - internal typescript API
return !!node.localSymbol?.exportSymbol;
}

Expand All @@ -270,6 +272,6 @@ export class SchemaGenerator {
}

protected getFullName(node: ts.Declaration, typeChecker: ts.TypeChecker): string {
return typeChecker.getFullyQualifiedName(node.symbol).replace(/".*"\./, "");
return typeChecker.getFullyQualifiedName(symbolAtNode(node)!).replace(/".*"\./, "");
}
}
3 changes: 2 additions & 1 deletion src/Utils/symbolAtNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type ts from "typescript";

export function symbolAtNode(node: ts.Node): ts.Symbol | undefined {
return (node as ts.Declaration).symbol;
//@ts-expect-error - internal typescript API
return node.symbol;
}
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1976,11 +1976,6 @@
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8"
integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==

"@types/ts-expose-internals@npm:ts-expose-internals@^5.4.5":
version "5.4.5"
resolved "https://registry.yarnpkg.com/ts-expose-internals/-/ts-expose-internals-5.4.5.tgz#94da2b665627135ad1281d98af3ccb08cb4c1950"
integrity sha512-0HfRwjgSIOyuDlHzkFedMWU4aHWq9pu4MUKHgH75U+L76wCAtK5WB0rc/dAIhulMRcPUlcKONeiiR5Sxy/7XcA==

"@types/yargs-parser@*":
version "21.0.3"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.3.tgz#815e30b786d2e8f0dcd85fd5bcf5e1a04d008f15"
Expand Down
Loading