Skip to content

Commit

Permalink
chore: add verbatim type specifier to export from statements (#2310)
Browse files Browse the repository at this point in the history
### 🎯 Goal

If we want the codebase to be compilable by tools like Vite, that use
esbuild under the hood to process files one-by-one, we should follow the
rules for isolated typescript modules.

Previously we were breaking the isolated modules rule by doing
re-exports like this one:

```ts
export { DefaultStreamChatGenerics, ChannelUnreadUiState } from './types';
```

Where both `DefaultStreamChatGenerics` and `ChannelUnreadUiState` are
types. When processing a single file, the compiler doesn't know if these
are types or not, and leaves the export statement as is, when really it
should be removed.

Fixing this by using verbatim module syntax:

```ts
export type { DefaultStreamChatGenerics, ChannelUnreadUiState } from './types';
```

After fixing all issues, `isolatedModules` was enabled in tsconfig.

A good side-effect of this change is that Ladle (which uses Vite
internally) now works again, which is crucial for e2e tests :)
  • Loading branch information
myandrienko authored Mar 5, 2024
1 parent d366ee4 commit 135e4c4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/Message/renderText/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { MentionProps } from './componentRenderers';
export type { MentionProps } from './componentRenderers';
export { escapeRegExp, matchMarkdownLinks, messageCodeBlocks } from './regex';
export * from './rehypePlugins';
export * from './remarkPlugins';
Expand Down
3 changes: 2 additions & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export * from './TypingIndicator';
export * from './UserItem';
export * from './Window';

export { UploadButton, UploadButtonProps } from './ReactFileUtilities';
export { UploadButton } from './ReactFileUtilities';
export type { UploadButtonProps } from './ReactFileUtilities';
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DefaultStreamChatGenerics, ChannelUnreadUiState } from './types';
export type { DefaultStreamChatGenerics, ChannelUnreadUiState } from './types';
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"declaration": true,
"declarationDir": "./dist",
"declarationMap": true,
"importHelpers": true
"importHelpers": true,
"isolatedModules": true
},
"include": ["./src/**/*"],
"exclude": ["./src/stories", "./src/mock-builders", "./src/**/__tests__/*"]
Expand Down

0 comments on commit 135e4c4

Please sign in to comment.