You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-13Lines changed: 24 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -2787,23 +2787,34 @@ You can see examples of these included in the built in type declarations in the
2787
2787
2788
2788
<!--START-SECTION:non-ts-files-->
2789
2789
2790
-
# Time to Really Learn TypeScript
2790
+
# Troubleshooting Handbook: Globals, Images and other non-TS files
2791
2791
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).
2793
2793
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`:
2795
2795
2796
-
It is worth mentioning some resources to help you get started:
2796
+
```ts
2797
+
declareglobal {
2798
+
interfaceWindow {
2799
+
MyVendorThing:MyVendorType;
2800
+
}
2801
+
}
2802
+
```
2797
2803
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
+
declaremodule"*.png";
2810
+
2811
+
// importing in a tsx file
2812
+
import*aslogofrom"./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)
0 commit comments