Skip to content

Commit 8f97a5e

Browse files
committed
Update srcts/README with info about window.Shiny
1 parent f55c26a commit 8f97a5e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

srcts/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
# Using Shiny TypeScript Definitions
22

3-
When developing TypeScript projects that use `window.Shiny`, we recommend installing the Shiny TypeScript definitions to your package. To install the latest stable definitions, call
3+
When developing TypeScript projects that use `window.Shiny`, we recommend installing the Shiny TypeScript definitions to your package. To install the latest stable definitions, run one of the following (depending on if you're using `npm` or `yarn`):
44

55
```bash
6-
yarn add https://github.com/rstudio/shiny\#v1.7.0
6+
npm install https://github.com/rstudio/shiny\#v1.10.0 --save-dev
7+
# or
8+
yarn add https://github.com/rstudio/shiny\#v1.10.0 --dev
79
```
810

9-
, matching the GitHub tag to your current the Shiny CRAN release (ex: `v1.7.0`). If you are asked to select a version of `@types/jquery`, please select the closest matching version.
11+
, matching the GitHub tag to your current the Shiny CRAN release (ex: `v1.10.0`). If you are asked to select a version of `@types/jquery`, please select the closest matching version.
1012

11-
This will provide a global type definition of `Shiny`, let your IDE know that `window.Shiny` is of type `Shiny`, and declare a globally available variable `Shiny` within your project. You **should not** need to import anything. Similar to `jQuery`, it should _Just Work_<sup>TM</sup>.
13+
This will provide a global type definition of `window.Shiny`. In your code, you can access the Shiny object via `window.Shiny` or just `Shiny`. However, note that if you are using TypeScript, it will be OK with `window.Shiny` but it will flag uses of `Shiny` (without the `window.` prefix), because TypeScript won't know that it's a global variable. We consider it better practice to use `window.Shiny` instead of `Shiny`, but if you want TypeScript to know that `Shiny` is available as a global variable, you can add the following to a TypeScript file in your code base.
14+
15+
```ts
16+
declare global {
17+
const Shiny: ShinyClass;
18+
}
19+
```
1220

1321
When loading your compiled file, it should be loaded after `shiny.js` is loaded. If you are using an `htmlDependency()` to add your code to the page, your script will automatically be loaded after has been loaded.
1422

0 commit comments

Comments
 (0)