Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 696 Bytes

learning_javascript_flow_generics.md

File metadata and controls

51 lines (36 loc) · 696 Bytes
path title
/learnings/javascript_flow_generics
Learning Javascript: Flow: Generics

Table Of Contents

Generics Experiments

/* @flow */

// compiles
function hi<T>( name: T): T {
  return name
}

console.log(hi("Bobby"))


// does not
function yo<T>( name: T): T {
  return 42
}

function yoma<T>( name: T): T {
  return "hi"
}

console.log(yo("Bobby"))
console.log( yoma("Ryan") )

// compiles (!!!!!)
function three<T>(first: T, second: T) {
  console.log(first, second)
}

three("world", 34)

// compiles
function four<T>(first: T, second: T): T {
  return first
}

four("world", 34)