Skip to content

This code produces a TypeError because it attempts to add a number and a string. TypeScript's type system catches this error during compilation.

Notifications You must be signed in to change notification settings

Bug-Hunter-X/Type-Error-in-TypeScript-Addition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

This repository demonstrates a common type error in TypeScript: attempting to perform an operation on incompatible types. The add function is explicitly typed to accept two numbers, but the call to add(1, "2") passes a string as the second argument. This leads to a compile-time error in TypeScript and a runtime error in JavaScript if the type checking is not enabled. The solution demonstrates how to use type guards or type assertions to handle potential type mismatches.

About

This code produces a TypeError because it attempts to add a number and a string. TypeScript's type system catches this error during compilation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published