Skip to content

Commit 7549a48

Browse files
committed
Add missing non-ts-files section
1 parent 4d5a46f commit 7549a48

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,23 +2787,34 @@ You can see examples of these included in the built in type declarations in the
27872787
27882788
<!--START-SECTION:non-ts-files-->
27892789
2790-
# Time to Really Learn TypeScript
2790+
# Troubleshooting Handbook: Globals, Images and other non-TS files
27912791
2792-
Believe it or not, we have only barely introduced TypeScript here in this cheatsheet. If you are still facing TypeScript troubleshooting issues, it is likely that your understanding of TS is still too superficial.
2792+
Use [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html).
27932793
2794-
There is a whole world of generic type logic that you will eventually get into, however it becomes far less dealing with React than just getting good at TypeScript so it is out of scope here. But at least you can get productive in React now :)
2794+
If, say, you are using a third party JS script that attaches on to the `window` global, you can extend `Window`:
27952795
2796-
It is worth mentioning some resources to help you get started:
2796+
```ts
2797+
declare global {
2798+
interface Window {
2799+
MyVendorThing: MyVendorType;
2800+
}
2801+
}
2802+
```
27972803
2798-
- Step through the 40+ examples under [the playground's](http://www.typescriptlang.org/play/index.html) Examples section, written by @Orta
2799-
- Anders Hejlsberg's overview of TS: https://www.youtube.com/watch?v=ET4kT88JRXs
2800-
- Marius Schultz: https://blog.mariusschulz.com/series/typescript-evolution with an [Egghead.io course](https://egghead.io/courses/advanced-static-types-in-typescript)
2801-
- Basarat's Deep Dive: https://basarat.gitbook.io/typescript/
2802-
- Axel Rauschmeyer's [Tackling TypeScript](https://exploringjs.com/tackling-ts/)
2803-
- Rares Matei: [Egghead.io course](https://egghead.io/courses/practical-advanced-typescript)'s advanced TypeScript course on Egghead.io is great for newer typescript features and practical type logic applications (e.g. recursively making all properties of a type `readonly`)
2804-
- Learn about [Generics, Conditional types and Mapped types](https://www.youtube.com/watch?v=PJjeHzvi_VQ&feature=youtu.be)
2805-
- Shu Uesugi: [TypeScript for Beginner Programmers](https://ts.chibicode.com/)
2806-
- Here is another [TypeScript Error Guide](https://github.com/threehams/typescript-error-guide/) that you can check for your errors.
2804+
Likewise if you wish to "import" an image or other non TS/TSX file:
2805+
2806+
```ts
2807+
// declaration.d.ts
2808+
// anywhere in your project, NOT the same name as any of your .ts/tsx files
2809+
declare module "*.png";
2810+
2811+
// importing in a tsx file
2812+
import * as logo from "./logo.png";
2813+
```
2814+
2815+
Note that `tsc` cannot bundle these files for you, you will have to use Webpack or Parcel.
2816+
2817+
Related issue: https://github.com/Microsoft/TypeScript-React-Starter/issues/12 and [StackOverflow](https://stackoverflow.com/a/49715468/4216035)
28072818
28082819
<!--END-SECTION:non-ts-files-->
28092820

genReadme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ async function main(argv) {
263263
from: currentReadme,
264264
to: pendingReadme,
265265
name: "non-ts-files",
266-
path: "docs/basic/troubleshooting/learn-ts.md",
266+
path: "docs/basic/troubleshooting/non-ts-files.md",
267267
headingLevel: 1,
268268
});
269269
pendingReadme = await updateSectionWith({

0 commit comments

Comments
 (0)