File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
10
10
11
11
For a steady stream of TILs, [ sign up for my newsletter] ( https://tinyletter.com/jbranchaud ) .
12
12
13
- _ 1042 TILs and counting..._
13
+ _ 1043 TILs and counting..._
14
14
15
15
---
16
16
@@ -50,6 +50,7 @@ _1042 TILs and counting..._
50
50
* [ Shell] ( #shell )
51
51
* [ Tailwind CSS] ( #tailwind-css )
52
52
* [ tmux] ( #tmux )
53
+ * [ TypeScript] ( #typescript )
53
54
* [ Unix] ( #unix )
54
55
* [ Vercel] ( #vercel )
55
56
* [ Vim] ( #vim )
@@ -944,6 +945,10 @@ _1042 TILs and counting..._
944
945
- [ tmux in your tmux] ( tmux/tmux-in-your-tmux.md )
945
946
- [ Toggle Between Two Common Sessions] ( tmux/toggle-between-two-common-sessions.md )
946
947
948
+ ### TypeScript
949
+
950
+ - [ Re-Export An Imported Type] ( typescript/re-export-an-imported-type.md )
951
+
947
952
### Unix
948
953
949
954
- [ All The Environment Variables] ( unix/all-the-environment-variables.md )
Original file line number Diff line number Diff line change
1
+ # Re-Export An Imported Type
2
+
3
+ I have a TypeScript module that is defining an XState machine. Among other
4
+ things, it imports the ` DoneEventObject ` type from ` xstate ` . I want to
5
+ re-export that type so that any modules using this machine have access to that
6
+ type definition.
7
+
8
+ This can be done a couple of ways. One way to import it under an aliased name
9
+ and then assign + export it using the original name.
10
+
11
+ ``` typescript
12
+ import {Machine , DoneEventObject as _DoneEventObject } from ' xstate'
13
+
14
+ export type DoneEventObject = _DoneEventObject
15
+ ` ` `
16
+
17
+ This works, but adds some potential indirection and confusion through the
18
+ double assignment.
19
+
20
+ Another way of doing this is to reference the type off the import statement as
21
+ part of an assignment.
22
+
23
+ ` ` ` typescript
24
+ import {Machine } from ' xstate'
25
+
26
+ export type DoneEventObject = import (' xstate' ).DoneEventObject
27
+ ` ` `
28
+
29
+ This imports, assigns, and exports the type in a single statement.
30
+
31
+ [source](https://github.com/microsoft/TypeScript/issues/28481#issuecomment-552938424)
You can’t perform that action at this time.
0 commit comments