Conversation
|
maybe we should start thinking of breaking this file into smaller files |
I don't expect it will grow much after this |
src/content/docs/curriculum-help.mdx
Outdated
| ```js | ||
| const explorer = await __helpers.Explorer(code); | ||
| assert.isTrue( | ||
| explorer.classes.Spam.methods.method.hasReturnAnnotation('number') |
There was a problem hiding this comment.
Maybe use a different method name like get42 so it's clear that it's not part of the chain
There was a problem hiding this comment.
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.
src/content/docs/curriculum-help.mdx
Outdated
| 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 |
There was a problem hiding this comment.
This example seems fine. Maybe add the suggested interface, though. Up to you.
| #### `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 | ||
| ``` |
There was a problem hiding this comment.
It's not completely obvious that this is the expected behaviour, so I would update the wording.
Checklist:
Update index.md)Closes #XXXXX
Work in progress. A few other methods will be added soon.