You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1404,6 +1404,39 @@ function foo(bar: string) {
1404
1404
typeFooReturn=ReturnType<typeoffoo>; // { baz: number }
1405
1405
```
1406
1406
1407
+
In fact you can grab virtually anything public: [see this blogpost from Ivan Koshelev](http://ikoshelev.azurewebsites.net/search/id/11/Pragmatic-uses-of-TypeScript-type-system-My-type-of-type)
1408
+
1409
+
```ts
1410
+
function foo() {
1411
+
return {
1412
+
a: 1,
1413
+
b: 2,
1414
+
subInstArr: [{
1415
+
c: 3,
1416
+
d: 4
1417
+
}]
1418
+
}
1419
+
}
1420
+
1421
+
typeInstType=ReturnType<typeoffoo>
1422
+
typeSubInstArr=InstType['subInstArr'];
1423
+
typeSubIsntType=SubInstArr[0];
1424
+
1425
+
letbaz: SubIsntType= {
1426
+
c: 5,
1427
+
d: 6// type checks ok!
1428
+
}
1429
+
1430
+
//You could just write a one-liner,
1431
+
//But please make sure it is forward-readable
1432
+
//(you can understand it from reading once left-to-right with no jumps)
0 commit comments