Comments (10)
Hi, thanks for your interest!
Can you show a quick example of what you mean (i.e. how do you organise the files, reference them etc.)?
I haven't really done anything with namespaces so far, so I can't quite imagine what it would look like.
Thanks!
from typegen.
We haven't decided yet how we want to organize files exactly, we just started to look into TypeScript so nothing has been decided yet.
But what we had in mind so far is to have .d.ts
files instead of .ts
files, something like:
declare module Models {
export interface SomeModel {
PropA: boolean;
PropB: number;
}
}
this would then allow us to access all our models with Models.SomeModel
, without having to explicitly import
them everywhere.
For example ReinforcedTypings has the option to export files as "pure typings" (.d.ts) or normal modules (.ts), but it has a few other problems which make it unsuitable for our use case. For example it doesn't export types which don't have an explicit attribute set. TypeGen does this nicely, though having potentially multiple .ts files for the same types is a bit of a problem, because we can't set ExportTs
attributes to every class and enum we want to export (this is mainly because our frontend uses some backend enums, and we don't want to clutter backend enums with frontend specific attributes.)
So what would work perfectly in our case would be something like this:
- Add
ExportTs
attributes to our UI models - Let TypeGen export types which don't have an explicit
ExportTs
attribute - Save the result in a single
.d.ts
file. This would also solve the problem with ending up with multiple files for the same types
Of course all of this could be made optional, either through the global config or additional attribute parameters. Would you be interested in a PR? I could try to come up with a proof of concept and then we could discuss this further.
from typegen.
Thanks for your response with the example.
From what I understand, you'd like to export multiple model classes (belonging to a single module) into one .d.ts
file - is that correct?
Unfortunately, this is not currently supported. I will look into this use case and see if I can implement it in the future. However, I can already see that implementing it would require a major change (i.e. it would be a pretty heavy task), so please don't expect this functionality in the nearest future.
In the meantime, have you tried TypeLITE? I think it exports classes per-module to a single file, so maybe this would be closer to what you're looking for.
from typegen.
Yes, either everything in a single .d.ts
file, or as individual files, but without duplicates (regarding types that don't have an explicit ExportTs
attribute)
And yes, I looked into TypeLITE, plus every other C# to TS converter I could find. The first problem I faced with every tool is that they don't work with our assembly out of the box, because we have an indirect reference to a native x64 DLL, and programs that target AnyCPU
are unable to load our assembly (throws a BadImageFormatException
). For example I couldn't figure out how to make the TypeLITE text template load our assembly. Same issue with the TypeGen CLI, but thanks to the programmatic API, I was able to create a custom x64 console app.
Additionally, TypeGen is so far the only tool which provides almost all features that we need. That's why I'm going to fork TypeGen and extend it, because we definitely need a C# to TS generator rather sooner than later.
I'll try to get a preliminary pull request ready today so you can take a first look at what I had in mind and then you can decide if you'd like to have this additional functionality in TypeGen.
from typegen.
Ahh, I'm dumb, TypeLITE isn't actually a pure text template implementation, but is backed by a class library, so I could also use it directly. I'll take a look and see how it fits our needs. Thanks so far!
from typegen.
Glad I could help, at least by "re-directing" you to TypeLITE :)
If you happen to modify TypeGen, I'd be happy to look at the pull request to see how I could fit it with the rest. Of course if TypeLITE turns out to be fine for you, I won't expect you to do that ;)
from typegen.
Hi @jburzynski, sorry for the late update! There are too many other priorities I have to take care of first before I can continue on this.
Anyway, I looked into TypeLITE around two weeks ago, and it does almost what we need. I took a look at the code and it is much more complex than TypeGen, and so I started to modify TypeGen with the features I proposed. It basically works, but it is more or less just a hack/proof of concept right now. I'll clean it up a bit and make a pull request for further discussion, and maybe we can come up with something. I hope I'll be able to make the pull request ready this week, but no promise. Otherwise next week or so :)
from typegen.
Hi, good to hear back from you :)
I'm glad you managed to make it work. Yes, I'll definitely look into the pull request. You don't need to hurry, as I'm also quite busy at the moment, so I may not be able to look into it immediately; but I'll definitely take care of it in some reasonable future ;)
I only closed this issue because it "aged" too much. But since it's still valid, I'm reopening it.
from typegen.
Hi @jburzynski, I have not forgotten or given up on this issue :) I still haven't had much time to further work on this, but I will prepare a pull request tomorrow with what I have so far, which then could serve as a discussion basis for further changes/improvements. There is no time pressure on this, so you can take a look whenever you have the time.
from typegen.
Great, thanks for working on this :)
I'll see what I can do!
from typegen.
Related Issues (20)
- Error after update from 4.0.1 to 4.1.0
- Preserving Directory and Sub-directory Structure in Generated TypeScript Files HOT 2
- Inheritance does not work when registration is done using AddInterface HOT 3
- Overriding OnAfterGeneration does not work, HOT 2
- Intermittent interface inheritance
- TsTypeUnion only works in top level export
- Requesting improvements to CustomTypeMappings
- csNullableTranslation with null|optional values
- changing typeScriptFileExtension to a different dot-seperated extension does not update import statements
- [feat]: Ignore specific interfaces HOT 2
- Project Url still points to https://jburzynski.net/TypeGen/ HOT 1
- Interface dependencies no longer generated across multiple 'outputDir' directories HOT 2
- Issue with generics inheritance HOT 2
- How can I get rid of Typegen.Core.dll in the redist
- Invalid export for `System.Tuple` type HOT 1
- Programmatical API: Could not load file or assembly 'Namotion.Reflection
- Typegen used old net6.0 binaries from my project instead of net8.0 HOT 1
- Add a configuration option for Unix vs. Windows-style line endings
- Static members should always be ignored when generating interfaces
- Get-only C# properties should generate readonly TS properties
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typegen.