Adding Types to an Existing Project
Gradually. All at once is how migrations fail and get reverted.
allowJs lets typed and untyped files coexist. Rename one file to .ts, fix what appears, commit, repeat. Type the boundaries first, because that is where the payoff is: API responses, shared utilities, anything used in many places.
@ts-expect-error rather than @ts-ignore. Both silence the next line. The difference is that @ts-expect-error becomes an error itself once the problem is fixed, so it cleans itself up. @ts-ignore stays forever, silently, long after it stopped being needed.
Third-party types. Most libraries ship their own. If an import errors with 'could not find a declaration file', try the @types package for it. A library with no types at all can be declared minimally in a .d.ts rather than left as any.
Mark this lesson complete
Signed in, your progress follows you to every device.