-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #79
- Loading branch information
Showing
4 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# TypeScript ([#79](https://github.com/observablehq/cli/issues/79)) | ||
|
||
[Observable Markdown](./markdown) also supports TypeScript, by simply stripping type information from code enclosed in TypeScript fenced code blocks, as well as from imported ts files. | ||
|
||
````md | ||
```ts | ||
TypeScript code here… | ||
``` | ||
```` | ||
|
||
```ts show | ||
function add(a: number, b: number): number { | ||
return a + b; | ||
} | ||
``` | ||
|
||
The resulting function can be called from js cells as well as other ts cells: | ||
|
||
```js show | ||
add(1, 3) | ||
``` | ||
|
||
```ts show | ||
add(1 as number, 3) | ||
``` | ||
|
||
Inline expressions are also converted when they appear to be written in TypeScript: | ||
|
||
```md | ||
1 + 2 = ${add(1 as number, 2)}. | ||
``` | ||
|
||
1 + 2 = ${add(1 as number, 2)}. | ||
|
||
|
||
Errors show up as expected: | ||
|
||
```ts show | ||
function bad() ::: { | ||
return a + b; | ||
} | ||
``` | ||
|
||
TODO. Imports are transpiled too: | ||
|
||
```ts show | ||
import {sum} from "./sum.ts" | ||
display(sum); | ||
display(sum(1, 2)); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters