Skip to main content

What does "strict typing" mean?

Strict typing means a language does not allow implicit (automatic) conversion of a value from one type to another if that could lead to unexpected behavior. Simply put, TypeScript requires you to explicitly respect types and not mix, for example, string and number without an explicit conversion.


1. Example of "loose" typing (JavaScript)

JavaScript is a dynamically and weakly typed language, so it will try on its own to convert types to the needed form:

javascript
console.log("5" - 1); // 4 ← the string "5" is implicitly converted to a number console.log("5" + 1); // "51" ← here, conversely, a number became a string console.log(true + 1); // 2

This behavior often causes unpredictable errors.


2. Example of strict typing (TypeScript)

TypeScript is a strictly typed language. It does not allow "mixing" types without your permission:

javascript
let count: number = 5; count = "5"; // Error: type string is not assignable to type number console.log("5" - 1); // Error at compile time

If you still need to convert a type, do it explicitly:

javascript
let num = Number("5"); // Explicit conversion of a string to a number console.log(num - 1); // 4

3. Difference between "strict" and "weak" typing

PropertyStrict typingWeak typing
Type conversionOnly explicitOften implicit
Compatibility checkAt compile timeAt runtime
Example languagesTypeScript, Java, C#, RustJavaScript, PHP, Python
Behavior for "5" + 1Error"51"
Behavior for "5" - 1Error4

4. Why it matters

Strict typing helps:

  • prevent hidden bugs and errors;
  • make code predictable and safe;
  • improve long-term maintainability and project scaling;
  • get accurate IDE hints and autocomplete.

Summary

Strict typing is a principle by which a language strictly controls type compatibility and does not perform implicit conversions, so the programmer always consciously manages data types.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.