I have been experimenting with supporting typescript with scaffold_golem(react = TRUE) and scaffold_leprechaun(react=TRUE). I think a react_ts option could be added to support react & typescript developement, similarly for vue.
Here are some changes based on the scaffold I found working for react
In tsconfig.json
- add
moduleReolution: 'node' to allow import statement
- add
allowSyntheticDefaultImports: true to allow default import such as import React from "react" instead of import * as React from 'react'
- add
jsx: "react" or jsx: "react-jsx"
- add
lib: ["dom"] to support types like HTMLElement
In srcjs/config/entry_points.json, change index to index.tsx or index.ts
{"index": "./srcjs/index.tsx"}
In srcjs/config/loaders.json, add ts-loader or esbuild-loader as mentioned in #6
[
{
"test": "\\.(js|jsx)$",
"use": [
"babel-loader"
],
"exclude": "/node_modules/"
},
{
"test": "\\.tsx?$",
"use": "ts-loader",
"exclude": "/node_modules/"
}
]
Install type files for react and react-dom
npm install --save-dev @types/react @types/react-dom
Install type files for shiny (or add a global.d.ts declaration file)
npm install --save-dev @types/rstudio-shiny
I have been experimenting with supporting typescript with
scaffold_golem(react = TRUE)andscaffold_leprechaun(react=TRUE). I think areact_tsoption could be added to support react & typescript developement, similarly forvue.Here are some changes based on the scaffold I found working for react
In
tsconfig.jsonmoduleReolution: 'node'to allow import statementallowSyntheticDefaultImports: trueto allow default import such asimport React from "react"instead ofimport * as React from 'react'jsx: "react"orjsx: "react-jsx"lib: ["dom"]to support types likeHTMLElementIn
srcjs/config/entry_points.json, change index toindex.tsxorindex.tsIn
srcjs/config/loaders.json, addts-loaderoresbuild-loaderas mentioned in #6[ { "test": "\\.(js|jsx)$", "use": [ "babel-loader" ], "exclude": "/node_modules/" }, { "test": "\\.tsx?$", "use": "ts-loader", "exclude": "/node_modules/" } ]Install type files for react and react-dom
Install type files for shiny (or add a
global.d.tsdeclaration file)