1# Instructions for Logging Issues 2 3## 1. Read the FAQ 4 5Please [read the FAQ](https://github.com/Microsoft/TypeScript/wiki/FAQ) before logging new issues, even if you think you have found a bug. 6 7Issues that ask questions answered in the FAQ will be closed without elaboration. 8 9## 2. Search for Duplicates 10 11[Search the existing issues](https://github.com/Microsoft/TypeScript/search?type=Issues) before logging a new one. 12 13Some search tips: 14 * *Don't* restrict your search to only open issues. An issue with a title similar to yours may have been closed as a duplicate of one with a less-findable title. 15 * Check for synonyms. For example, if your bug involves an interface, it likely also occurs with type aliases or classes. 16 * Search for the title of the issue you're about to log. This sounds obvious but 80% of the time this is sufficient to find a duplicate when one exists. 17 * Read more than the first page of results. Many bugs here use the same words so relevancy sorting is not particularly strong. 18 * If you have a crash, search for the first few topmost function names shown in the call stack. 19 20## 3. Do you have a question? 21 22The issue tracker is for **issues**, in other words, bugs and suggestions. 23If you have a *question*, please use [Stack Overflow](https://stackoverflow.com/questions/tagged/typescript), [Gitter](https://gitter.im/Microsoft/TypeScript), your favorite search engine, or other resources. 24Due to increased traffic, we can no longer answer questions in the issue tracker. 25 26## 4. Did you find a bug? 27 28When logging a bug, please be sure to include the following: 29 * What version of TypeScript you're using (run `tsc --v`) 30 * If at all possible, an *isolated* way to reproduce the behavior 31 * The behavior you expect to see, and the actual behavior 32 33You can try out the nightly build of TypeScript (`npm install typescript@next`) to see if the bug has already been fixed. 34 35## 5. Do you have a suggestion? 36 37We also accept suggestions in the issue tracker. 38Be sure to [check the FAQ](https://github.com/Microsoft/TypeScript/wiki/FAQ) and [search](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=is%3Aissue) first. 39 40In general, things we find useful when reviewing suggestions are: 41* A description of the problem you're trying to solve 42* An overview of the suggested solution 43* Examples of how the suggestion would work in various places 44 * Code examples showing e.g. "this would be an error, this wouldn't" 45 * Code examples showing the generated JavaScript (if applicable) 46* If relevant, precedent in other languages can be useful for establishing context and expected behavior 47 48# Instructions for Contributing Code 49 50## What You'll Need 51 520. [A bug or feature you want to work on](https://github.com/microsoft/TypeScript/labels/help%20wanted)! 531. [A GitHub account](https://github.com/join). 542. A copy of the TypeScript code. See the next steps for instructions. 553. [Node](https://nodejs.org), which runs JavaScript locally. Current or LTS will both work. 564. An editor. [VS Code](https://code.visualstudio.com) is the best place to start for TypeScript. 575. The gulp command line tool, for building and testing changes. See the next steps for how to install it. 58 59## Get Started 60 611. Install node using the version you downloaded from [nodejs.org](https://nodejs.org). 622. Open a terminal. 633. Make a fork—your own copy—of TypeScript on your GitHub account, then make a clone—a local copy—on your computer. ([Here are some step-by-step instructions](https://github.com/anitab-org/mentorship-android/wiki/Fork%2C-Clone-%26-Remote)). Add `--depth=1` to the end of the `git clone` command to save time. 644. Install the gulp command line tool: `npm install -g gulp-cli` 655. Change to the TypeScript folder you made: `cd TypeScript` 666. Install dependencies: `npm ci` 677. Make sure everything builds and tests pass: `gulp runtests-parallel` 688. Open the TypeScript folder in your editor. 699. Follow the directions below to add and debug a test. 70 71## Helpful tasks 72 73Running `gulp --tasks --depth 1` provides the full listing, but here are a few common tasks you might use. 74 75``` 76gulp local # Build the compiler into built/local. 77gulp clean # Delete the built compiler. 78gulp LKG # Replace the last known good with the built one. 79 # Bootstrapping step to be executed when the built compiler reaches a stable state. 80gulp tests # Build the test infrastructure using the built compiler. 81gulp runtests # Run tests using the built compiler and test infrastructure. 82 # You can override the specific suite runner used or specify a test for this command. 83 # Use --tests=<testPath> for a specific test and/or --runner=<runnerName> for a specific suite. 84 # Valid runners include conformance, compiler, fourslash, project, user, and docker 85 # The user and docker runners are extended test suite runners - the user runner 86 # works on disk in the tests/cases/user directory, while the docker runner works in containers. 87 # You'll need to have the docker executable in your system path for the docker runner to work. 88gulp runtests-parallel # Like runtests, but split across multiple threads. Uses a number of threads equal to the system 89 # core count by default. Use --workers=<number> to adjust this. 90gulp baseline-accept # This replaces the baseline test results with the results obtained from gulp runtests. 91gulp lint # Runs eslint on the TypeScript source. 92gulp help # List the above commands. 93``` 94 95## Tips 96 97### Using a development container 98 99If you prefer to develop using containers, this repository includes a [development container](https://code.visualstudio.com/docs/remote/containers) that you can use to quickly create an isolated development environment with all the tools you need to start working on TypeScript. To get started with a dev container and VS Code, either: 100 101- Clone the TypeScript repository locally and use the `Open Folder in Container` command. 102- Use the `Clone Repository in Container Volume` command to clone the TypeScript repository into a new container. 103 104### Faster clones 105 106The TypeScript repository is relatively large. To save some time, you might want to clone it without the repo's full history using `git clone --depth=1`. 107 108### Filename too long on Windows 109 110You might need to run `git config --global core.longpaths true` before cloning TypeScript on Windows. 111 112### Using local builds 113 114Run `gulp` to build a version of the compiler/language service that reflects changes you've made. You can then run `node <repo-root>/built/local/tsc.js` in place of `tsc` in your project. For example, to run `tsc --watch` from within the root of the repository on a file called `test.ts`, you can run `node ./built/local/tsc.js --watch test.ts`. 115 116## Contributing bug fixes 117 118TypeScript is currently accepting contributions in the form of bug fixes. A bug must have an issue tracking it in the issue tracker that has been approved (labelled ["help wanted"](https://github.com/Microsoft/TypeScript/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) or in the "Backlog milestone") by the TypeScript team. Your pull request should include a link to the bug that you are fixing. If you've submitted a PR for a bug, please post a comment in the bug to avoid duplication of effort. 119 120## Contributing features 121 122Features (things that add new or improved functionality to TypeScript) may be accepted, but will need to first be approved (labelled ["help wanted"](https://github.com/Microsoft/TypeScript/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) or in the "Backlog" milestone) by a TypeScript project maintainer in the suggestion issue. Features with language design impact, or that are adequately satisfied with external tools, will not be accepted. 123 124## Issue claiming 125 126If you intend to work on an issue, please avoid leaving comments like "I'm going to work on this". There are a few reasons for this. These comments tend to [discourage anyone from working in the area](https://devblogs.microsoft.com/oldnewthing/20091201-00/?p=15843), yet many issues are much more difficult than they first appear, and you might find yourself trying to fix several issues before finding one that can be completed. Many issues have a long trail of people indicating that they're going to try to fix it, but no PR. 127 128Conversely, you do not need to ask anyone's permission before starting work on an issue marked as "help wanted". It's always fine to try! We ask that you choose issues tagged in the "Backlog" milestone as these are issues that we've identified as needing fixes / implementations. 129 130The sheer quantity of open issues, combined with their general difficulty, makes it extremely unlikely that you and another contributor are a) working on the same issue and b) both going to find a solution. 131 132## Legal 133 134You will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you are granting us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under appropriate copyright. Upon submitting a pull request, you will automatically be given instructions on how to sign the CLA. 135 136## Housekeeping 137 138Your pull request should: 139 140* Include a description of what your change intends to do 141* Be based on reasonably recent commit in the **main** branch 142* Include adequate tests 143 * At least one test should fail in the absence of your non-test code changes. If your PR does not match this criteria, please specify why 144 * Tests should include reasonable permutations of the target fix/change 145 * Include baseline changes with your change 146* Follow the code conventions described in [Coding guidelines](https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines) 147* To avoid line ending issues, set `autocrlf = input` and `whitespace = cr-at-eol` in your git configuration 148 149## Force-pushing 150 151Avoid force-pushing your changes, especially when updating your PR based on review feedback. Force-pushed changes are not easily viewable on GitHub, and not at all viewable if a force-push also rebases against main. TypeScript PRs are squash merged, so the specific commits on your PR branch do not matter, only the PR title itself. Don't worry about having a perfect commit history; instead focus on making your changes as easy to review and merge as possible. 152 153## Contributing `lib.d.ts` fixes 154 155There are three relevant locations to be aware of when it comes to TypeScript's library declaration files: 156 157* `src/lib`: the location of the sources themselves. 158* `lib`: the location of the last-known-good (LKG) versions of the files which are updated periodically. 159* `built/local`: the build output location, including where `src/lib` files will be copied to. 160 161Any changes should be made to [src/lib](https://github.com/Microsoft/TypeScript/tree/main/src/lib). **Most** of these files can be updated by hand, with the exception of any generated files (see below). 162 163Library files in `built/local/` are updated automatically by running the standard build task: 164 165```sh 166gulp 167``` 168 169The files in `lib/` are used to bootstrap compilation and usually **should not** be updated unless publishing a new version or updating the LKG. 170 171### Modifying generated library files 172 173The files `src/lib/dom.generated.d.ts` and `src/lib/webworker.generated.d.ts` both represent type declarations for the DOM and are auto-generated. To make any modifications to them, you will have to direct changes to https://github.com/Microsoft/TSJS-lib-generator 174 175## Documentation on TypeScript Compiler 176 177If you need a head start understanding how the compiler works, or how the code in different parts of the compiler works, there is a separate repo: [TypeScript Compiler Notes](https://github.com/microsoft/TypeScript-Compiler-Notes). As the name implies, it contains notes understood by different engineers about different parts of the compiler. 178 179## Running the Tests 180 181To run all tests, invoke the `runtests-parallel` target using gulp: 182 183```Shell 184gulp runtests-parallel 185``` 186 187This will run all tests; to run only a specific subset of tests, use: 188 189```Shell 190gulp runtests --tests=<regex> 191``` 192 193e.g. to run all compiler baseline tests: 194 195```Shell 196gulp runtests --tests=compiler 197``` 198 199or to run a specific test: `tests\cases\compiler\2dArrays.ts` 200 201```Shell 202gulp runtests --tests=2dArrays 203``` 204 205## Debugging the tests 206 207You can debug with VS Code or Node instead with `gulp runtests -i`: 208 209```Shell 210gulp runtests --tests=2dArrays -i 211``` 212 213You can also use the [provided VS Code launch configuration](./.vscode/launch.template.json) to launch a debug session for an open test file. Rename the file 'launch.json', open the test file of interest, and launch the debugger from the debug panel (or press F5). 214 215## Adding a Test 216 217To add a new test case, add a `.ts` file in `tests\cases\compiler` with code that shows the bug is now fixed, or your new feature now works. 218 219These files support metadata tags in the format `// @metaDataName: value`. 220The supported names and values are the same as those supported in the compiler itself, with the addition of the `fileName` flag. 221`fileName` tags delimit sections of a file to be used as separate compilation units. 222They are useful for testing modules. 223See below for examples. 224 225**Note** that if you have a test corresponding to a specific area of spec compliance, you can put it in the appropriate subfolder of `tests\cases\conformance`. 226**Note** that test filenames must be distinct from all other test names, so you may have to work a bit to find a unique name if it's something common. 227 228### Tests for multiple files 229 230When you need to mimic having multiple files in a single test to test features such as "import", use the `filename` tag: 231 232```ts 233// @filename: file1.ts 234export function f() { 235} 236 237// @filename: file2.ts 238import { f as g } from "file1"; 239 240var x = g(); 241``` 242 243## Managing the baselines 244 245Most tests generate "baselines" to find differences in output. 246As an example, compiler tests usually emit one file each for 247 248- the `.js` and `.d.ts` output (all in the same `.js` output file), 249- the errors produced by the compiler (in an `.errors.txt` file), 250- the types of each expression (in a `.types` file), 251- the symbols for each identifier (in a `.symbols` file), and 252- the source map outputs for files if a test opts into them (in a `.js.map` file). 253 254When a change in the baselines is detected, the test will fail. To inspect changes vs the expected baselines, use 255 256```Shell 257git diff --diff-filter=AM --no-index ./tests/baselines/reference ./tests/baselines/local 258``` 259 260Alternatively, you can set the `DIFF` environment variable and run `gulp diff`, or manually run your favorite folder diffing tool between `tests/baselines/reference` and `tests/baselines/local`. Our team largely uses Beyond Compare and WinMerge. 261 262After verifying that the changes in the baselines are correct, run 263 264```Shell 265gulp baseline-accept 266``` 267 268This will change the files in `tests\baselines\reference`, which should be included as part of your commit. 269Be sure to validate the changes carefully -- apparently unrelated changes to baselines can be clues about something you didn't think of. 270 271## Localization 272 273All strings the user may see are stored in [`diagnosticMessages.json`](./src/compiler/diagnosticMessages.json). 274If you make changes to it, run `gulp generate-diagnostics` to push them to the `Diagnostic` interface in `diagnosticInformationMap.generated.ts`. 275 276See [coding guidelines on diagnostic messages](https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines#diagnostic-messages). 277