Skip to content

docs: add TS helpers#1236

Open
Dario-DC wants to merge 5 commits intofreeCodeCamp:mainfrom
Dario-DC:add-ts-helpers-docs
Open

docs: add TS helpers#1236
Dario-DC wants to merge 5 commits intofreeCodeCamp:mainfrom
Dario-DC:add-ts-helpers-docs

Conversation

@Dario-DC
Copy link
Contributor

@Dario-DC Dario-DC commented Mar 9, 2026

Checklist:

Closes #XXXXX

Work in progress. A few other methods will be added soon.

@Dario-DC Dario-DC marked this pull request as ready for review March 13, 2026 12:01
@Dario-DC Dario-DC requested a review from a team as a code owner March 13, 2026 12:01
@majestic-owl448
Copy link
Contributor

maybe we should start thinking of breaking this file into smaller files

@Dario-DC
Copy link
Contributor Author

maybe we should start thinking of breaking this file into smaller files

I don't expect it will grow much after this

```js
const explorer = await __helpers.Explorer(code);
assert.isTrue(
explorer.classes.Spam.methods.method.hasReturnAnnotation('number')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a different method name like get42 so it's clear that it's not part of the chain

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds documentation for a new set of TypeScript AST “Explorer” helpers to the curriculum helper docs, intended to guide challenge authors in writing TypeScript-focused assertions.

Changes:

  • Documented __helpers.Explorer(code) basic usage for parsing camper TypeScript.
  • Added a catalog of Explorer properties/methods (e.g., variables, classes, hasReturnAnnotation, hasTypeProps, etc.) with examples.
  • Included examples for class/type/interface inspection and modifier checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1543 to +1547
const explorer = new Explorer('class Foo extends Bar { }');
const { Foo } = explorer.classes;
Foo.doesExtend('Bar'); // true
Foo.doesExtend(['Bar', 'Baz']); // true only if both are extended
Foo.doesExtend('Baz'); // false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example seems fine. Maybe add the suggested interface, though. Up to you.

Comment on lines +1504 to +1513
#### `isUnionOf(types: string[])`

Returns `true` if the current node has a union type annotation that includes all specified types, ignoring order.

```js
const explorer = new Explorer('const a: number | string | boolean;');
const { a } = explorer.variables;
a.annotation.isUnionOf(['number', 'string', 'boolean']); // true
a.annotation.isUnionOf(['number', 'string']); // false
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not completely obvious that this is the expected behaviour, so I would update the wording.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants