-
-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change .d.ts files to .ts files #1135
Comments
The arguments make sense to me regarding not having to use However, I do believe we need to try and separate type definition exports from code files wherever possible, for the time-being. Here are my reasons: We've always had to import types with:
instead of:
because our build system does not support it as default, even though it is the typescript convention. I hoped when we can make this change in the future, using separate
If we export all type definitions from
If we ever type The suggestion of using a single file does not solve the problem at hand which is the slow down of development velocity. The actual solution we need is to be able to do this:
without running into issues with vite, svelte, jest and storybook. When we started the project there was an open issue on the svelte repo regarding this and I believe I read that the error was due to vite. I remember there was an update later which allowed a config value we can set inorder for us to import types directly without using Whoever works on this issue should find the status of that config, modify our configuration, and then make the other suggested changes mentioned in this issue's description.
I remember mentioning these points in that call but I don't think you saw the issues around I'll leave it to you to go through this comment and ask questions and/or update the issue description. |
I'm sorry @pavish I still don't understand 😕 Would you be able to provide a concrete example of the problem which I can reproduce (like I did in the "More type safety and easier refactoring" section of my comment)? |
@seancolsen Okay, let me try explaining this with an example.
The reason behind this is that Svelte (or Vite) does not allow importing type definitions without the use of Inorder to avoid such issues, I began moving type definitions from code to separate files. So, every module would contain an Another decision I took was to use .d.ts like What I'm in agreement with:
What I'm not in agreement with (for the time being):
I've not kept in touch with the latest updates to this import issue, anyone working on our ticket should figure that out before moving type exports to |
Ok I see what you're talking about now. Thank you for providing the example. Yes I already encounter that problem daily-ish. It's a nuisance, and I can see how it would get worse, were we to put all the re-exports in the same file. I support splitting the re-exports up into separate files -- a file |
I've marked this as "ready" now that we seem to be in agreement about the next steps.
I'm not sure we can change all the |
Context
*.d.ts
in certain specific scenarios.Meta
class and a lot of surrounding code. #1109. So I'm raising the concern again, this time with stronger arguments.Request
I'd like to stop using
*.d.ts
files, moving all their contents to*.ts
files instead.For situations where we want to export types which are relevant to a specific component, we currently have:
Icon.svelte
Icon.d.ts
I'd like to change the pattern to:
Icon.svelte
iconUtils.ts
For situations where we're re-exporting stuff, we currently have:
index.ts
types.d.ts
I'd like to move everything to
index.ts
.Rationale
More type safety and easier refactoring
It seems to me that TypeScript does not check
*.d.ts
files with the same rigor that it checks*.ts
files.Follow me on an example...
In
src/stores/table-data/types.d.ts
, change:to
Note that
columns.ts
has no exportedDisplay
member. TypeScript sees no problem in with this change intypes.d.ts
though! Not good. Code like that in a*.ts
file would immediately be complaining at me.Running
svelte-check
produces no errors! Really? That can't be. Let's look atRowCell.svelte
which importsDisplay
from'@mathesar/stores/table-data/types'
.All properties of
Display
(e.g.handleKeyEventsOnActiveCell
) are now typed asany
. Ugh! And we don't even get linting errors about theany
types!This leads to some bugs during refactoring that can be trickier to track down.
In the above example,
Display
is already exported fromsrc/stores/table-data/index.ts
. So withinRowCell.svelte
, we can import it with:I don't see the use of also exporting it from
src/stores/table-data/types.d.ts
.Simplicity
It's simpler to have one TypeScript file type. Fewer decisions to make when adding new files. It's especially simpler when re-exporting stuff because all the re-exports can go in one file instead of two.
Easier auto-imports
Let's say I want to use
AbstractTypeResponse
(defined inApp.d.ts
). When I let VS Code auto-import that type, it gives:But this is problematic because some module loaders will see
'@mathesar/App'
and have difficulty resolving the ambiguity between'@mathesar/App.svelte'
and'@mathesar/App.d.ts'
. I've run into this within our codebase before. I can't remember the exact steps I took to reproduce the problem, but I do remember that I had to add.d
on the end of my import it to get it to work. It may have been a problem loading imports while running Jest or Storybook. That's additional friction that would not be present when importing fromappUtils.ts
.Issues with enums
Some
*.d.ts
files contain enums. That's problematic because enums are not strictly types -- but also objects used at runtime. In #1109 I hit this issue when running tests from atest.ts
files. Jest was unable to find the runtime value for the enum. I had to moveTabularType
out of a*d.ts
file just to get my test to run. All enums should be moved to.ts
files. The fact that we even need to think about this demonstrates the additional overhead that comes with our pattern of using*.d.ts
files.Consistency with TypeScript community norms
For example...
https://www.reddit.com/r/typescript/comments/t23p7o/confused_on_use_of_dts_file_in_reacttypescript_app/
https://www.reddit.com/r/typescript/comments/r69jmi/whats_the_difference_between_ts_and_dts_file/
https://www.reddit.com/r/typescript/comments/rirjiw/when_do_you_use_dts_files_and_when_do_you_use_ts/
https://www.reddit.com/r/typescript/comments/rz62fa/dts_files_vs_ts_can_someone_clear_this_up_for_me/?sort=top
I couldn't find a single case of someone arguing to use
*.d.ts
file like we're using them.The text was updated successfully, but these errors were encountered: