-
Notifications
You must be signed in to change notification settings - Fork 0
/
video09.js
35 lines (31 loc) · 872 Bytes
/
video09.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// @flow
// ============================== Пример на классах
class User {}
class Owner extends User {}
class Admin extends Owner {}
class BaseProcessor {
getRelatedOwner(owner: Owner): Owner {
return owner
}
}
class ChildProcessor extends BaseProcessor {
// input: User <---(can) Owner (not)---> Admin // ковариантность
// output: User <---(not) Owner (can)---> Admin // контрвариантность
getRelatedOwner(owner: User): Admin {
declare var o: Admin
return o
}
}
// ======================================
function logger(entity: { name: ?string }) {
console.log(entity.name)
}
function loggerWithReadOnly(entity: { +name: ?string }) {
console.log(entity.name)
}
type Entity = {
name: string
}
const user: Entity = { name: 'Vasya' }
// logger(user) -> error
loggerWithReadOnly(user) // -> ok