0

Almost all definition files so readily available you know where, do a declare module or declare var. Isn't this a huge problem? If I forget to import an implementation of a declared module and then use it, compiler will never give me an error, but the app will crash horribly at run time.

One way I see how to solve this is to write definition files only with a declare module "topLevelName", so you can't accidentally use it without requiring it first. But this creates a problem for things such as jQuery, because people tend to not require it but just put it into global context. In this case current approach is actually working correctly.

I just can't seem to wrap my head around this huge limitation of the system. Am I missing something?

1
  • 1
    TypeScript doesn't verify that all of the compiled output files are actually included on the page either, since there could be a a.ts and b.ts, but the page contains only <script src="a.js"></script>. Commented Sep 1, 2014 at 10:53

1 Answer 1

1

If I forget to import an implementation of a declared module and then use it, compiler will never give me an error, but the app will crash horribly at run time.

Yes

Isn't this a huge problem

Not really. The likelyhood of adding a types but forgetting to include the JavaScript is not very high with beginner level experience.

Am I missing something?

no.

More

A bigger problem is type compatability between libs e.g different TypeScript libraries depending up different editions of JQuery.

Sign up to request clarification or add additional context in comments.

1 Comment

When you are structuring your app using CommonJS or AMD the likelihood of forgetting to require a file is very high, since you have to do it in each file that uses that specific library. The likelihood of forgetting to include a script tag is certainly very small, but that is only if you are okay with globals (and/or not working with NodeJS). I'll accept your answer because it's seems your point of view is being shared among most Typescript developers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.