DEV Community

Introduction to TypeScript. Function Types (opens in new tab)

Discussed on DEV

Basic syntax Since everything in TypeScript has to have type, functions are also wrapped in the type system: inputs must have types, output must have one, let's look at the example: function add(x: number, y: number): number { return x + y; } console.log(add(1, 3)); //4 Actually, we don't have to explicitly assign type for an ouput: function add(x: number, y: number) { return x + y; } console.log(add(1, 3)); //4 The compiler won't see any problem with it, since it implicitly set number type f...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help