Headshot of Marius Schulz
Marius Schulz Front End Engineer

TypeScript 2.1: Untyped Imports

TypeScript 2.1 makes it a lot easier to work with untyped imports. Previously, the compiler was overly strict and would give you an error when you imported a module that doesn't ship with type definitions:

TypeScript error: untyped import

Starting with TypeScript 2.1, the compiler will no longer complain if there are no type declarations for a module. TypeScript is happy with untyped modules and your editor doesn't render red squigglies anymore:

Untyped imports work just fine in TypeScript 2.1

Now, the imported range function is typed as any. The upside to this is that migrating an existing JavaScript project to TypeScript should lead to fewer compile-time errors. The downside is that you won't get any autocompletion suggestions or fine-grained type checking since the compiler doesn't know anything about the module or its exports.

If you later provide type declarations, e.g. via a type declaration package from npm, they will take priority over the default any type. (Otherwise, there would be no way to provide types for imported modules.)

Note that untyped imports will still be flagged as errors if you're compiling your project with the noImplicitAny option set to true — after all, the imports are now implicitly typed as any. To make the error go away, you can either provide type declarations or set the noImplicitAny compiler option to false.

This post is part of the TypeScript Evolution series:

  1. TypeScript 2.0: Non-Nullable Types
  2. TypeScript 2.0: Control Flow Based Type Analysis
  3. TypeScript 2.0: Acquiring Type Declaration Files
  4. TypeScript 2.0: Read-Only Properties
  5. TypeScript 2.0: Tagged Union Types
  6. TypeScript 2.0: More Literal Types
  7. TypeScript 2.0: The never Type
  8. TypeScript 2.0: Built-In Type Declarations
  9. TypeScript 2.1: async/await for ES3/ES5
  10. TypeScript 2.1: External Helpers Library
  11. TypeScript 2.1: Object Rest and Spread
  12. TypeScript 2.1: keyof and Lookup Types
  13. TypeScript 2.1: Mapped Types
  14. TypeScript 2.1: Improved Inference for Literal Types
  15. TypeScript 2.1: Literal Type Widening
  16. TypeScript 2.1: Untyped Imports
  17. TypeScript 2.2: The object Type
  18. TypeScript 2.2: Dotted Properties and String Index Signatures
  19. TypeScript 2.2: Null-Checking for Expression Operands
  20. TypeScript 2.2: Mixin Classes
  21. TypeScript 2.3: Generic Parameter Defaults
  22. TypeScript 2.3: The --strict Compiler Option
  23. TypeScript 2.3: Type-Checking JavaScript Files with --checkJs
  24. TypeScript 2.3: Downlevel Iteration for ES3/ES5
  25. TypeScript 2.4: String Enums
  26. TypeScript 2.4: Weak Type Detection
  27. TypeScript 2.4: Spelling Correction
  28. TypeScript 2.4: Dynamic import() Expressions
  29. TypeScript 2.5: Optional catch Binding
  30. TypeScript 2.6: JSX Fragment Syntax
  31. TypeScript 2.7: Numeric Separators
  32. TypeScript 2.7: Strict Property Initialization
  33. TypeScript 2.8: Per-File JSX Factories
  34. TypeScript 2.8: Conditional Types
  35. TypeScript 2.8: Mapped Type Modifiers