Skip to content

Template for react with typescript #17

@qiushiyan

Description

@qiushiyan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions