Skip to content

Commit 07d34ab

Browse files
authored
Merge pull request #584 from forivall/patch-1
Add alternative way to get property type
2 parents da0851e + 2f18bc1 commit 07d34ab

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

docs/types/moving-types.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,19 @@ bar = '789'; // ERROR: Type `string` is not `assignable` to type `number`
4242

4343
## Capturing the type of a class member
4444

45-
Similar to capturing the type of a variable, you just declare a variable purely for type capturing purposes:
45+
You can traverse into any non-nullable object type to retrieve the type of a property:
4646

4747
```ts
4848
class Foo {
4949
foo: number; // some member whose type we want to capture
5050
}
5151

52+
let bar: Foo['foo']; // `bar` has type `number`
53+
```
54+
55+
Alternatively, similar to capturing the type of a variable, you just declare a variable purely for type capturing purposes:
56+
57+
```ts
5258
// Purely to capture type
5359
declare let _foo: Foo;
5460

0 commit comments

Comments
 (0)