Skip to content

Commit e94a6af

Browse files
authored
🤖 Merge PR DefinitelyTyped#73453 Add types for treescape by @Shan0102
1 parent 40519b3 commit e94a6af

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

types/treescape/.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts

types/treescape/index.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export class TreeNode {
2+
val: number;
3+
left: TreeNode | null;
4+
right: TreeNode | null;
5+
constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null);
6+
}
7+
/**
8+
* Creates a binary tree from a level-order array (use `null` for empty nodes).
9+
* @param arr Level-order array representing the tree.
10+
* @returns The root TreeNode or null if the array is empty.
11+
*/
12+
export function convertToTree(arr: (number | null)[]): TreeNode | null;
13+
14+
/**
15+
* Prints the tree in ASCII format to the console.
16+
* @param treeNode The root TreeNode to print.
17+
*/
18+
export function printTree(treeNode: TreeNode | null): void;

types/treescape/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"private": true,
3+
"name": "@types/treescape",
4+
"version": "1.0.9999",
5+
"projects": [
6+
"https://www.npmjs.com/package/treescape"
7+
],
8+
"devDependencies": {
9+
"@types/treescape": "workspace:."
10+
},
11+
"owners": [
12+
{
13+
"name": "Shan0102",
14+
"githubUsername": "Shan0102"
15+
}
16+
]
17+
}

types/treescape/treescape-tests.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { convertToTree, printTree } from "treescape";
2+
3+
const tree = convertToTree([1, 2, 3, null, 4, 5, 6]);
4+
printTree(tree);

types/treescape/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"module": "node16",
4+
"lib": ["es6"],
5+
"noImplicitAny": true,
6+
"noImplicitThis": true,
7+
"strictNullChecks": true,
8+
"strictFunctionTypes": true,
9+
"types": [],
10+
"noEmit": true,
11+
"forceConsistentCasingInFileNames": true
12+
},
13+
"files": ["index.d.ts", "treescape-tests.ts"]
14+
}

0 commit comments

Comments
 (0)