Skip to content

Commit

Permalink
Add support for TS 5.2
Browse files Browse the repository at this point in the history
Resolves #2374
Resolves #2373
Resolves #2369

Co-Authored-By: Michaël Vanderheyden <hello@th3s4mur41.me>
  • Loading branch information
Gerrit0 and Th3S4mur41 committed Aug 25, 2023
1 parent 5c977ae commit c83f2c3
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

- @camc314
- @cprussin
- @Th3S4mur41

## v0.24.8 (2023-06-04)

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"shiki": "^0.14.1"
},
"peerDependencies": {
"typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x"
"typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x"
},
"devDependencies": {
"@types/lunr": "^2.3.4",
Expand All @@ -47,7 +47,7 @@
"prettier": "3.0.1",
"puppeteer": "^13.5.2",
"ts-node": "^10.9.1",
"typescript": "5.1.6"
"typescript": "5.2.2"
},
"files": [
"/bin",
Expand Down
27 changes: 14 additions & 13 deletions scripts/rebuild_specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ const { basename } = require("path");
const base = path.join(__dirname, "../src/test/converter");

async function getApp() {
const app = new td.Application();
app.options.addReader(new td.TSConfigReader());
await app.bootstrap({
name: "typedoc",
excludeExternals: true,
disableSources: false,
tsconfig: path.join(base, "tsconfig.json"),
externalPattern: ["**/node_modules/**"],
entryPointStrategy: td.EntryPointStrategy.Expand,
logLevel: td.LogLevel.Warn,
gitRevision: "fake",
readme: "none",
});
const app = await td.Application.bootstrap(
{
name: "typedoc",
excludeExternals: true,
disableSources: false,
tsconfig: path.join(base, "tsconfig.json"),
externalPattern: ["**/node_modules/**"],
entryPointStrategy: td.EntryPointStrategy.Expand,
logLevel: td.LogLevel.Warn,
gitRevision: "fake",
readme: "none",
},
[new td.TSConfigReader()],
);
app.serializer.addSerializer({
priority: -1,
supports(obj) {
Expand Down
18 changes: 10 additions & 8 deletions src/lib/converter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,14 +921,16 @@ const tupleConverter: TypeConverter<ts.TupleTypeNode, ts.TupleTypeReference> = {

if (type.target.labeledElementDeclarations) {
const namedDeclarations = type.target.labeledElementDeclarations;
elements = elements?.map(
(el, i) =>
new NamedTupleMember(
namedDeclarations[i].name.getText(),
!!namedDeclarations[i].questionToken,
removeUndefined(el),
),
);
elements = elements?.map((el, i) => {
const namedDecl = namedDeclarations[i];
return namedDecl
? new NamedTupleMember(
namedDecl.name.getText(),
!!namedDecl.questionToken,
removeUndefined(el),
)
: el;
});
}

elements = elements?.map((el, i) => {
Expand Down
21 changes: 21 additions & 0 deletions src/test/behavior.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,27 @@ describe("Behavior Tests", () => {
);
});

it("Handles named tuple declarations", () => {
const project = convert("namedTupleMembers");

equal(
query(project, "PartiallyNamedTuple").type?.toString(),
"[name: string, number]",
);
equal(
query(project, "PartiallyNamedTuple2").type?.toString(),
"[name?: string, number?]",
);
equal(
query(project, "PartiallyNamedTupleRest").type?.toString(),
"[name?: string, ...number[]]",
);
equal(
query(project, "partiallyNamedTupleRest").type?.toString(),
"[name?: string, ...number[]]",
);
});

it("Handles overloads", () => {
const project = convert("overloads");
const foo = query(project, "foo");
Expand Down
10 changes: 10 additions & 0 deletions src/test/converter2/behavior/namedTupleMembers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type PartiallyNamedTuple = [name: string, number];

export type PartiallyNamedTuple2 = [name?: string, number?];

export type PartiallyNamedTupleRest = [name?: string, ...number[]];

export const partiallyNamedTupleRest = {} as any as [
name?: string,
...number[],
];

0 comments on commit c83f2c3

Please sign in to comment.