Skip to content

Commit ad414c5

Browse files
committed
add some basic .d.ts instructions
1 parent 864443b commit ad414c5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

ADVANCED.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,15 +880,29 @@ An example github repository with a project showing how to integrate [eslint + t
880880

881881
## Working with Non-TypeScript Libraries (writing your own index.d.ts)
882882

883-
_Not written yet._
883+
Lets say you want to use `de-indent`, but it isn't typed or on DefinitelyTyped. You get an error like this:
884884

885-
Please contribute on this topic! [We have an ongoing issue here with some references](https://github.com/sw-yx/react-typescript-cheatsheet/issues/8).
885+
```
886+
[ts]
887+
Could not find a declaration file for module 'de-indent'. '/Users/swyx/Work/react-sfc-loader/node_modules/de-indent/index.js' implicitly has an 'any' type.
888+
Try `npm install @types/de-indent` if it exists or add a new declaration (.d.ts) file containing `declare module 'de-indent';` [7016]
889+
```
890+
891+
So create a `.d.ts` file anywhere in your project with the module definition:
892+
893+
```ts
894+
// de-indent.d.ts
895+
declare module 'de-indent' {
896+
function deindent(): void
897+
export = deindent // default export
898+
}
899+
```
886900
887901
<details>
888902
889903
<summary>Further Discussion</summary>
890904
891-
We have more discussion and examples [in our issue here](https://github.com/sw-yx/react-typescript-cheatsheet/issues/12).
905+
Any other tips? Please contribute on this topic! [We have an ongoing issue here with some references](https://github.com/sw-yx/react-typescript-cheatsheet/issues/8). We have more discussion and examples [in our issue here](https://github.com/sw-yx/react-typescript-cheatsheet/issues/12).
892906
893907
</details>
894908

0 commit comments

Comments
 (0)