Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - TypeScript Support Doc #466

Merged
merged 6 commits into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion source/_data/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ guides:
screenshots-and-videos: screenshots-and-videos.html
launching-browsers: launching-browsers.html
web-security: web-security.html
reporters: reporters.html
tooling:
plugins-guide: plugins-guide.html
reporters: reporters.html
typescript-support: typescript-support.html

# advanced-cypress:
# the-cypress-workflow: the-cypress-workflow.html
# coming-from-selenium: coming-from-selenium.html
Expand Down
4 changes: 4 additions & 0 deletions source/api/introduction/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Each document attempts to cover the essentials of each method including:

**See also:** Other related methods.

# IntelliSense

IntelliSense is available for Cypress. It offers intelligent parameter information when writing Cypress commands directly in your IDE. {% url "Learn how to set up IntelliSense." typescript-support#IntelliSense %}

# Reporting a Problem

If you spot a typo, broken link, incorrect code sample or want to contribute to improve the documentation, we're happy to have your help!
Expand Down
File renamed without changes.
45 changes: 45 additions & 0 deletions source/guides/tooling/typescript-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: TypeScript Support
comments: false
---

Cypress ships with {% url "official type declarations" https://github.com/cypress-io/cypress/tree/develop/cli/types %} for {% url "TypeScript" https://www.typescriptlang.org/ %}.

# IntelliSense

IntelliSense is available for Cypress. It offers intelligent parameter information directly in your IDE while writing tests. While TypeScript is used to generate the data for intellisense, you can make use of intellisense even when writing your tests in plain JavaScript.

## Triple-Slash Directives

Adding a {% url "triple-slash directive" "http://www.typescriptlang.org/docs/handbook/triple-slash-directives.html" %} to the head of your JavaScript or TypeScript testing file should get intellisense working in most IDEs.

```js
/// <reference types="Cypress" />
```
{% img /img/guides/typescript-intellisense-with-reference.gif %}

## tsconfig.json

If you want to write your tests in TypeScript, you may find it more convenient to add a {% url "`tsconfig.json`" http://www.typescriptlang.org/docs/handbook/tsconfig-json.html %} inside your `cypress` folder.

```json
{
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"],
},
"include": [
"**/*.ts"
]
}
```

The `"types"` will tell the TypeScript compiler to only include type definitions from Cypress. This will address instances where the project also uses `@types/chai` or `@types/jquery`. Since {% url "Chai" bundled-tools#Chai %} and {% url "jQuery" bundled-tools#Other-Library-Utilities %} are namespaces (globals), incompatible versions will cause the package manager (`yarn` or `npm`) to nest and include multiple definitions and cause conflicts.

# Examples

- {% url "TypeScript with WebPack" https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/preprocessors__typescript-webpack %}
- {% url "TypeScript with Browserify" https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/preprocessors__typescript-browserify %}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions themes/cypress/languages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ sidebar:
cypress-api-design: API Design
all-videos: Videos
plugins-guide: Plugins
tooling: Tooling
typescript-support: TypeScript Support
api:
introduction: Introduction
api: API
Expand Down