From 4168724c2a9f4e53bf439ff67aecabba35e5e6be Mon Sep 17 00:00:00 2001 From: John Dance Date: Wed, 1 Sep 2021 13:45:45 -0700 Subject: [PATCH] update documentation for types --- docs/trex_typescript.md | 73 +++++++++++++++++------------------------ package-lock.json | 6 ++-- package.json | 2 +- 3 files changed, 35 insertions(+), 46 deletions(-) diff --git a/docs/trex_typescript.md b/docs/trex_typescript.md index 14aa91de..892fc1a3 100644 --- a/docs/trex_typescript.md +++ b/docs/trex_typescript.md @@ -7,8 +7,8 @@ The Extensions API is a JavaScript library. If you author in TypeScript, Tableau **In this section** -* TOC -{:toc} +- TOC + {:toc}
Note If you want to examine and use TypeScript versions of several of the sample extensions in the Samples folder, see Samples-Typescript (GitHub) and follow the instructions to Use the TypeScript Samples.
@@ -29,44 +29,39 @@ Import the Extensions API type definitions into your TypeScript code. It is best For example, to import the module, `Parameter`, from `@tableau/extensions-api-types` you would use the following: - ```javascript - - import { Parameter } from '@tableau/extensions-api-types'; - - ``` - - If you want to use Tableau enumerations as parameters to functions, or as a member variables inside class definitions, you need to import the type definitions from `@tableau/extensions-api-types/ExternalContract/Namespaces/Tableau`. You can then declare parameters or variables of that type. - For example, to be able to use the `DataType` enum as a parameter to a function, you need to use the following import statement: - - ```javascript +```javascript +import { Parameter } from "@tableau/extensions-api-types"; +``` - import { DataType } from '@tableau/extensions-api-types/ExternalContract/Namespaces/Tableau'; +If you want to use Tableau enumerations as parameters to functions, or as a member variables inside class definitions, you need to import the type definitions from `@tableau/extensions-api-types`. You can then declare parameters or variables of that type. +For example, to be able to use the `DataType` enum as a parameter to a function, you need to use the following import statement: - ``` +```javascript +import { DataType } from "@tableau/extensions-api-types"; +``` - You can then use `DataType` as a type for a parameter in a class method. You can't use the fully qualified name as a parameter type (`tableau.DataType`), even though you can use the fully qualified name within a method. +You can then use `DataType` as a type for a parameter in a class method. You can't use the fully qualified name as a parameter type (`tableau.DataType`), even though you can use the fully qualified name within a method. - ```javascript - private foo(value: DataType) { +```javascript + private foo(value: DataType) { - switch (value) { - case tableau.DataType.String: - console.log(value); - break; - // ... do other things - } - } + switch (value) { + case tableau.DataType.String: + console.log(value); + break; + // ... do other things + } +} - ``` +``` +Please note that `@tableau/extension-api-types` submodules are subject to change. Import only from `@tableau/extensions-api-types`. ## Set compiler options for type definitions You can set the `tsc` compiler options in the `tsconfig.json` file for the project. You can set the `typeRoots` option to point to the folder that contains the Extensions API type definitions. The following example is used for the sample extensions in the Samples-Typescript folder. In the `tsconfig.json` file, the `typeRoots` options includes the `./node_modules/@tableau` path. The TypeScript samples use Node.js and webpack to build the extensions. - ```json - { "compilerOptions": { /* Basic Options */ @@ -78,37 +73,31 @@ You can set the `tsc` compiler options in the `tsconfig.json` file for the proje "typeRoots": ["./node_modules/@tableau", "./node_modules/@types"] } } - - - ``` ## Compile your code with the TypeScript compiler If you need to install the compiler, see [TypeScript in Visual Studio Code](https://code.visualstudio.com/docs/languages/typescript?=target="_blank"). Visual Studio Code supports TypeScript, but does not automatically include the TypeScript compiler (`tsc`). The TypeScript compiler transpiles your TypeScript source code to JavaScript. You include the JavaScript output in your extension `.html` file(s). - ## Use the compiled JavaScript output in your extension -The TypeScript compiler (`tsc`) transpiles the source code into JavaScript. You just need to include the path to the JavaScript file in your extension code. +The TypeScript compiler (`tsc`) transpiles the source code into JavaScript. You just need to include the path to the JavaScript file in your extension code. -For example, the extensions in the Samples-Typescript folder all link to Extensions API JavaScript library `tableau.extensions.1.latest.js` and to the compiled JavaScript file for the extension (not the TypeScript source file). +For example, the extensions in the Samples-Typescript folder all link to Extensions API JavaScript library `tableau.extensions.1.latest.js` and to the compiled JavaScript file for the extension (not the TypeScript source file). In the HTML code for the extensions, the JavaScript files are referenced. The following example, links to the `datasources.js` file. ```html - - - - - - + + + + ``` ## Related resources -* [TypeScript](https://www.typescriptlang.org/index.html?=target="_blank") +- [TypeScript](https://www.typescriptlang.org/index.html?=target="_blank") -* [TypeScript in Visual Studio Code](https://code.visualstudio.com/docs/languages/typescript?=target="_blank") +- [TypeScript in Visual Studio Code](https://code.visualstudio.com/docs/languages/typescript?=target="_blank") -* [TypeScript Sample Extensions (GitHub)](https://github.com/tableau/extensions-api/tree/master/Samples-TypeScript) and [Use the TypeScript samples]({{site.baseurl}}/docs/trex_examples.html#use-the-typescript-samples) +- [TypeScript Sample Extensions (GitHub)](https://github.com/tableau/extensions-api/tree/master/Samples-TypeScript) and [Use the TypeScript samples]({{site.baseurl}}/docs/trex_examples.html#use-the-typescript-samples) diff --git a/package-lock.json b/package-lock.json index debff449..a6cb8f38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,9 +33,9 @@ } }, "@tableau/extensions-api-types": { - "version": "1.6.0-pre.16", - "resolved": "https://artifactory.prod.tableautools.com/artifactory/api/npm/tab-npm/@tableau/extensions-api-types/-/@tableau/extensions-api-types-1.6.0-pre.16.tgz", - "integrity": "sha1-+/+VOkMcU9XG4s2O/TaxUPx+XhE=", + "version": "1.6.0-pre.17", + "resolved": "https://artifactory.prod.tableautools.com/artifactory/api/npm/tab-npm/@tableau/extensions-api-types/-/@tableau/extensions-api-types-1.6.0-pre.17.tgz", + "integrity": "sha1-H2vt2OSTdOhLZ5MrJwOlvqixljU=", "dev": true, "requires": { "@types/lodash": "^4.14.126" diff --git a/package.json b/package.json index 0a4b4bcd..5d9a182c 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "http-server": "^0.12.3" }, "devDependencies": { - "@tableau/extensions-api-types": "1.6.0-pre.16", + "@tableau/extensions-api-types": "1.6.0-pre.17", "@tableau/tabextsandbox": "^1.1.0", "@types/jquery": "^3.3.29", "concurrently": "^6.2.1",