You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document provides a concise guide for writing TypeScript fourslash tests and compiler tests, along with build instructions.
3
+
The repo is large and the project is complex.
4
+
This document contains information you'll need no matter what the task is, but we have a separate library of content that you'll need to consult depending on the issue.
4
5
5
-
## Build Instructions Summary
6
+
You have been given the `md-fragments` MCP server.
7
+
Before doing anything, query its `list-topics` endpoint and remember all the topics you saw.
8
+
Consult these topics often, as they contain important information relevant to the work.
6
9
7
-
### Setup
8
-
1. Install Node.js (current or LTS)
9
-
2. Clone the repository: `git clone --depth=1 https://github.com/microsoft/TypeScript`
10
-
3. Install dependencies: `npm ci`
10
+
Before you end a session, read the `How to Finish a Session` topic.
11
11
12
-
### Common Build Tasks
13
-
```bash
14
-
npx hereby local# Build the compiler into built/local
15
-
npx hereby clean # Delete the built compiler
16
-
npx hereby tests # Build the test infrastructure
17
-
npx hereby runtests # Run all tests
18
-
npx hereby runtests-parallel # Run tests in parallel (recommended)
19
-
npx hereby runtests --runner=fourslash # Run only fourslash tests
20
-
npx hereby runtests --runner=compiler # Run only compiler tests
21
-
npx hereby runtests --tests=<testPath># Run specific test
22
-
npx hereby baseline-accept # Accept new test baselines
23
-
npx hereby lint # Run eslint
24
-
npx hereby format # Run code formatting
25
-
```
26
-
27
-
## Fourslash Test Syntax Guide
28
-
29
-
Fourslash tests are interactive TypeScript language service tests. They validate IDE features like completions, quick info, navigation, and refactoring.
30
-
31
-
### Basic Structure
32
-
```typescript
33
-
/// <referencepath='fourslash.ts'/>
34
-
35
-
////code goes here with /*markers*/
36
-
37
-
// Test assertions go here
38
-
```
39
-
40
-
### Key Syntax Elements
41
-
42
-
#### 1. Source Code Definition
43
-
Use `////` to define source code lines:
44
-
```typescript
45
-
////function foo(x: number) {
46
-
//// return x + 1;
47
-
////}
48
-
////let result = foo(/*marker*/42);
49
-
```
50
-
51
-
#### 2. Markers for Positioning
52
-
Use `/**/` for anonymous markers or `/*name*/` for named markers:
53
-
```typescript
54
-
////let x = /*1*/someValue;
55
-
////let y = /*cursor*/anotherValue;
56
-
```
57
-
58
-
#### 3. Multi-file Tests
59
-
Use `// @Filename:` to define multiple files:
60
-
```typescript
61
-
// @Filename: /a.ts
62
-
////export const value = 42;
63
-
64
-
// @Filename: /b.ts
65
-
////import { value } from './a';
66
-
////console.log(/*marker*/value);
67
-
```
68
-
69
-
#### 4. Ranges
70
-
Use `[|text|]` to define text ranges:
71
-
```typescript
72
-
////function test() {
73
-
//// [|return 42;|]
74
-
////}
75
-
```
76
-
77
-
### Common API Patterns
78
-
79
-
#### Navigation & Positioning
80
-
```typescript
81
-
goTo.marker("markerName"); // Navigate to marker
82
-
goTo.marker(); // Navigate to anonymous marker /**/
Compiler tests validate TypeScript compilation behavior, type checking, and error reporting.
14
+
We want to make you smarter over time.
15
+
If you encounter a situation where you think a developer on this project would be able to provide a useful answer *and* it's not something offered by the Documentation MCP server, add a question to the file `.github/copilot-questions.md`
16
+
Explain what you searched for so that we can put the right search terms in the documentation library.
146
17
147
-
### Basic Structure
148
-
- Simple `.ts` files in `tests/cases/compiler/`
149
-
- Use comments to indicate expected behavior
150
-
- No special test harness - just TypeScript code
18
+
## Common Commands
151
19
152
-
### Compiler Directives
153
-
Use `// @directive: value` for compiler options:
154
-
```typescript
155
-
// @strict: true
156
-
// @target: ES2015
157
-
// @lib: ES2015,DOM
20
+
You'll need to run these commands often. Always use `npx` to run `hereby` commands.
158
21
159
-
let x:string=42; // Error expected
160
-
```
161
-
162
-
### Common Directives
163
-
```typescript
164
-
// @strict: true/false
165
-
// @noImplicitAny: true/false
166
-
// @target: ES5/ES2015/ES2020/ESNext
167
-
// @module: commonjs/amd/es6/esnext
168
-
// @lib: ES5,DOM/ES2015/ES2020
169
-
// @declaration: true/false
170
-
// @skipLibCheck: true/false
171
-
```
172
-
173
-
### Multi-file Tests
174
-
```typescript
175
-
// @Filename: helper.ts
176
-
exportfunction helper(x:number):string {
177
-
returnx.toString();
178
-
}
179
-
180
-
// @Filename: main.ts
181
-
import { helper } from"./helper";
182
-
const result =helper(42);
183
-
```
184
-
185
-
### Error Expectations
186
-
Use comments to document expected behavior:
187
-
```typescript
188
-
abstractclassBase {
189
-
abstract method():void;
190
-
}
191
-
192
-
classDerivedextendsBase {
193
-
// Missing implementation - should error
194
-
}
195
-
196
-
newBase(); // Should error - cannot instantiate abstract class
197
-
```
198
-
199
-
### Type Testing Patterns
200
-
```typescript
201
-
// Test type inference
202
-
let inferred = [1, 2, 3]; // Should infer number[]
203
-
204
-
// Test type compatibility
205
-
typeA= { x:number };
206
-
typeB= { x:number; y:string };
207
-
let a:A= { x: 1 };
208
-
let b:B= { x: 1, y: "hello" };
209
-
a=b; // Should work - B is assignable to A
210
-
b=a; // Should error - A missing property y
211
-
```
212
-
213
-
### Simple Example
214
-
```typescript
215
-
// Test that optional properties work correctly
216
-
interfaceConfig {
217
-
required:string;
218
-
optional?:number;
219
-
}
220
-
221
-
const config1:Config= { required: "test" }; // Should work
222
-
const config2:Config= { required: "test", optional: 42 }; // Should work
0 commit comments