From aa55dc46804ca7aa19e8004664d22997a4289b1b Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Sat, 9 Mar 2019 23:44:06 -0700 Subject: [PATCH] typescript example --- examples/typescript/package.json | 19 ++++++++++++++ examples/typescript/routes/index.tsx | 39 ++++++++++++++++++++++++++++ examples/typescript/tsconfig.json | 8 ++++++ routes/typescript/index.tsx | 30 --------------------- 4 files changed, 66 insertions(+), 30 deletions(-) create mode 100644 examples/typescript/package.json create mode 100644 examples/typescript/routes/index.tsx create mode 100644 examples/typescript/tsconfig.json delete mode 100644 routes/typescript/index.tsx diff --git a/examples/typescript/package.json b/examples/typescript/package.json new file mode 100644 index 0000000..896d28b --- /dev/null +++ b/examples/typescript/package.json @@ -0,0 +1,19 @@ +{ + "private": true, + "name": "typescript-example", + "version": "0.0.0", + "devDependencies": { + "ts-node": "^8.0.3", + "typescript": "^3.3.3333" + }, + "scripts": { + "dev": "polydev --require ts-node/register", + "prestart": "tsc", + "start": "cd dist && NODE_ENV=production polydev" + }, + "dependencies": { + "@types/express": "^4.16.1", + "react": "^16.8.4", + "react-dom": "^16.8.4" + } +} diff --git a/examples/typescript/routes/index.tsx b/examples/typescript/routes/index.tsx new file mode 100644 index 0000000..882b608 --- /dev/null +++ b/examples/typescript/routes/index.tsx @@ -0,0 +1,39 @@ +import { Request, Response } from "express" +import * as React from "react" +import { renderToStaticMarkup } from "react-dom/server" + +let hits = 0 + +export default (req: Request, res: Response) => { + hits++ + + res.send( + renderToStaticMarkup( + <> + + + +
+ +
+
+

+ 👋 Howdy from TypeScript +

+ +

+ {hits} {hits ? "hits" : "hit"} +

+
+ + +
+ + ) + ) +} diff --git a/examples/typescript/tsconfig.json b/examples/typescript/tsconfig.json new file mode 100644 index 0000000..bf485d2 --- /dev/null +++ b/examples/typescript/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "allowJs": true, + "jsx": "react", + "outDir": "dist", + "rootDir": "." + } +} diff --git a/routes/typescript/index.tsx b/routes/typescript/index.tsx deleted file mode 100644 index d971a03..0000000 --- a/routes/typescript/index.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { Request, Response } from "express" - -let hits = 0 - -export default (req: Request, res: Response) => { - hits++ - - res.send(` - - - -
- -
-
-

- 👋 Howdy from TypeScript -

- -

- ${hits} ${hits ? "hits" : "hit"} -

-
- - -
- `) -}