or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-cra-template-typescript

The official TypeScript template for Create React App providing preconfigured TypeScript support and development environment setup.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/cra-template-typescript@1.3.x

To install, run

npx @tessl/cli install tessl/npm-cra-template-typescript@1.3.0

index.mddocs/

CRA Template TypeScript

The official TypeScript template for Create React App that provides a complete TypeScript development environment with preconfigured testing, linting, and type definitions. This template generates a React application with TypeScript support, eliminating manual configuration while providing modern development tooling and best practices.

Package Information

  • Package Name: cra-template-typescript
  • Package Type: npm (Create React App template)
  • Language: TypeScript
  • Installation: Used via Create React App CLI
  • Node.js: >=14.0.0

Core Usage

This template is used through the Create React App CLI to bootstrap new TypeScript React applications:

npx create-react-app my-app --template typescript

# or with yarn
yarn create react-app my-app --template typescript

# or with pnpm
pnpm create react-app my-app --template typescript

Basic Usage Example

# Create a new React TypeScript project
npx create-react-app my-typescript-app --template typescript

# Navigate to the project
cd my-typescript-app

# Start development server
npm start

# Run tests
npm test

# Build for production
npm run build

Architecture

The template generates a project with a well-defined architecture:

  • Entry Point (src/index.tsx): Application bootstrap using React 18's createRoot API
  • App Component (src/App.tsx): Main application component with TypeScript typing
  • Testing Setup (src/setupTests.ts, src/App.test.tsx): Jest + React Testing Library configuration
  • Performance Monitoring (src/reportWebVitals.ts): Web Vitals integration for Core Web Vitals measurement
  • Static Assets (public/): PWA-ready manifest, icons, and HTML template
  • TypeScript Configuration: Automatic tsconfig.json generation with Create React App defaults
  • Build System: Webpack-based build system via react-scripts (hidden from user)

Template Structure

Generated Project Structure

When used, this template creates the following project structure:

my-app/
├── public/
│   ├── index.html          # HTML template
│   ├── favicon.ico         # App icon
│   ├── logo192.png         # PWA icon (192x192)
│   ├── logo512.png         # PWA icon (512x512)
│   ├── manifest.json       # PWA manifest
│   └── robots.txt          # Search engine instructions
├── src/
│   ├── App.css             # App component styles
│   ├── App.test.tsx        # App component tests
│   ├── App.tsx             # Main App component
│   ├── index.css           # Global styles
│   ├── index.tsx           # Application entry point
│   ├── logo.svg            # React logo
│   ├── reportWebVitals.ts  # Performance monitoring
│   └── setupTests.ts       # Test environment setup
├── .gitignore              # Git ignore rules
├── package.json            # Dependencies and scripts
├── README.md               # Project documentation
└── tsconfig.json           # TypeScript configuration

Capabilities

Template Configuration

The template provides configuration through template.json:

{
  "package": {
    "dependencies": {
      "@testing-library/dom": "^10.4.0",
      "@testing-library/jest-dom": "^6.6.3", 
      "@testing-library/react": "^16.1.0",
      "@testing-library/user-event": "^13.2.1",
      "@types/jest": "^27.0.1",
      "@types/node": "^16.7.13",
      "@types/react": "^19.0.0",
      "@types/react-dom": "^19.0.0",
      "typescript": "^4.4.2",
      "web-vitals": "^2.1.0"
    },
    "eslintConfig": {
      "extends": ["react-app", "react-app/jest"]
    }
  }
}

Generated Components

App Component

Main application component with TypeScript typing:

// Generated in src/App.tsx
import React from 'react';

function App(): React.JSX.Element;
export default App;

The App component provides:

  • React logo display
  • Styled header section
  • Link to React documentation
  • Basic responsive layout

Entry Point

Application bootstrap with React 18+ patterns:

// Generated in src/index.tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import reportWebVitals from './reportWebVitals';

// Creates root container using React 18+ createRoot API
const root: ReactDOM.Root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);

// Renders app with StrictMode wrapper
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// Optional performance monitoring
reportWebVitals();

Generated README

The template includes a comprehensive README.md with project documentation:

# Generated README.md content includes:
- Project overview and Create React App attribution
- Available Scripts section (start, test, build, eject)
- Detailed script descriptions and usage instructions  
- Learn More section with links to documentation

Testing Setup

Test Configuration

// Generated in src/setupTests.ts
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
import '@testing-library/jest-dom';

Sample Test

// Generated in src/App.test.tsx
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';

// Jest test function signature
test(name: string, fn: () => void): void;

// Provided test example:
test('renders learn react link', () => {
  render(<App />);
  const linkElement = screen.getByText(/learn react/i);
  expect(linkElement).toBeInTheDocument();
});

Performance Monitoring

Web Vitals Integration

// Generated in src/reportWebVitals.ts
import { ReportHandler } from 'web-vitals';

// Main function for performance measurement
const reportWebVitals: (onPerfEntry?: ReportHandler) => void;

// Implementation uses dynamic import for better performance
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
  if (onPerfEntry && onPerfEntry instanceof Function) {
    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
      getCLS(onPerfEntry);  // Cumulative Layout Shift
      getFID(onPerfEntry);  // First Input Delay  
      getFCP(onPerfEntry);  // First Contentful Paint
      getLCP(onPerfEntry);  // Largest Contentful Paint
      getTTFB(onPerfEntry); // Time to First Byte
    });
  }
};

export default reportWebVitals;

The reportWebVitals function provides:

  • Core Web Vitals measurement (CLS, FID, FCP, LCP, TTFB)
  • Optional performance entry callback
  • Dynamic import of web-vitals library

TypeScript Configuration

The template includes comprehensive TypeScript configuration:

Type Definitions

Includes essential type packages:

  • @types/react - React component and hook types
  • @types/react-dom - ReactDOM types
  • @types/jest - Jest testing framework types
  • @types/node - Node.js API types

Generated TypeScript Config

Create React App automatically generates tsconfig.json with optimized settings:

// Auto-generated tsconfig.json includes:
{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "es6"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": ["src"]
}

ESLint Configuration

Preconfigured ESLint rules:

  • react-app - Core React development rules
  • react-app/jest - Jest testing environment rules

Progressive Web App Support

Manifest Configuration

// Generated in public/manifest.json
{
  "short_name": string;
  "name": string;
  "icons": Array<{
    "src": string;
    "sizes": string;
    "type": string;
  }>;
  "start_url": string;
  "display": string;
  "theme_color": string;
  "background_color": string;
}

Icons and Assets

Provides ready-to-use PWA assets:

  • favicon.ico - Browser tab icon
  • logo192.png - PWA icon for Android
  • logo512.png - PWA icon for iOS

Development Scripts

Generated package.json includes standard Create React App scripts:

{
  "scripts": {
    "start": "react-scripts start",     // Development server
    "build": "react-scripts build",     // Production build  
    "test": "react-scripts test",       // Test runner
    "eject": "react-scripts eject"      // Eject from CRA
  }
}

Environment Requirements

  • Node.js: Version 14.0.0 or higher
  • npm: Version 6+ (or yarn/pnpm equivalent)
  • Create React App: Latest version recommended

Generated Features

When this template is used, it creates a project with:

  1. TypeScript Support: Full type checking and IntelliSense
  2. Testing Environment: Jest + React Testing Library setup
  3. Development Server: Hot reload and error overlay
  4. Production Build: Optimized bundle with code splitting
  5. ESLint Integration: Code quality and style enforcement
  6. PWA Foundation: Manifest and icon structure
  7. Performance Monitoring: Web Vitals measurement setup
  8. Modern React Patterns: React 18+ with createRoot

Template Customization

The template can be extended by:

  • Adding additional dependencies to template.json
  • Modifying ESLint configuration
  • Including additional template files
  • Customizing the generated README content

Browser Support

Generated projects support:

  • Modern browsers (Chrome, Firefox, Safari, Edge)
  • Mobile browsers (Android Chrome, iOS Safari)
  • Configurable through browserslist in package.json