Adding Type Definitions for External Libraries
In this exercise, we are using an external library named diff
that is designed to compare two strings:
import Diff from "diff"; // red squiggly line under "diff"const message = "Hello, world!";const secondMessage = "Goodbye, world!";const diff = Diff.diffChars(message, secondMessage
Transcript
00:00 In this exercise, we are using an external library called diff. We have a message called hello world, and then a second message called goodbye world, and we're calling diff.diffchars message second message. This is a real library that's out there that you can use, but there's an issue with it. When you try to use it in TypeScript,
00:19 it's saying could not find a declaration file for module diff. Try npm isavediff types diff to see if it exists. Your job is to try to work out how to solve this error, and we're gonna talk through the method through which you solve it because it's very interesting. Good luck.