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';.