Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !5593

Refine how TypeScript types are handled

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/Timer/refactor/do-not-expose-types into master Oct 26, 2018
  • Overview 18
  • Commits 18
  • Pipelines 0
  • Changes 6

Created by: Timer

Right now, we copy our react-app.d.ts file into the user's source folder to register types for our webpack loaders, e.g.:

declare module '*.svg' {
  import * as React from 'react';

  export const ReactComponent: React.SFC<React.SVGProps<SVGSVGElement>>;

  const src: string;
  export default src;
}

declare module '*.module.css' {
  const classes: { [key: string]: string };
  export default classes;
}

I feel like this isn't very optimal, and I'd rather this be "encapsulated" somehow.

On first thought, it looks like we could publish @types/react-scripts and have the types automatically registered -- however, I'm not sure we want that maintenance overhead when the types field exists in package.json.

This pull request is exploring how we could rely on the types key so our types are always specific to the react-scripts version without relying on package manager hoisting metrics/external packages.


It looks like we can trigger TypeScript to import these types by specifiying "types": ["react-scripts"] in tsconfig.json, but this turns off the default behavior of absorbing the @types/ folder.

Also, using include in tsconfig.json seems suboptimal because we can't specify node_modules/react-scripts/config/react-app.d.ts since it might be hoisted.

I suppose the crux of the problem is there's never a time where someone would write import 'react-scripts';.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/Timer/refactor/do-not-expose-types