Skip to content

This code snippet demonstrates a common error in TypeScript related to type checking. The `greeter` function expects a string, but an array is passed. This results in a type error.

Notifications You must be signed in to change notification settings

Bug-Hunter-X/TypeScript-Type-Error--Passing-an-Array-to-a-Function-Expecting-a-String-3shke

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

TypeScript Type Error: Passing Array to String Function

This repository demonstrates a common TypeScript error: passing an array to a function expecting a string argument. The bug.ts file contains the erroneous code, while bugSolution.ts shows how to fix it.

Bug Description

The greeter function is defined to accept a string argument and return a greeting. However, an array of strings is passed as an argument, leading to a type error.

Solution

The solution involves either modifying the greeter function to accept an array of strings or modifying the call to the greeter function to pass a single string. The bugSolution.ts file provides corrected code.

About

This code snippet demonstrates a common error in TypeScript related to type checking. The `greeter` function expects a string, but an array is passed. This results in a type error.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published