-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Properties of type List<T> result in any[] even when T defined in same project #17
Comments
Fixing this depends on fixing #7 first, because you do not support generating anonymously typed collection properties. (The Anyway, once #7 is fixed, I have a potential workaround for what appears to be a Visual Studio 2017 issue (the fact that the
it works around the problem. The basic idea here is that before we call I would create a PR for this, but resolving #7 also requires #13 to be addressed, and I can't tell which way you actually want to go with #13 - you could fix it either by reverting to the Web Essentials 2015 file naming convention, or you could update the problematic code to work with the new convention. But since I don't know which of those you'd want, I can't create a suitable PR to fix #7 and #13 both of which need to be fixed to enable this issue to be fixed. |
Current output |
Please Try Build 1.1.24 to see if your issues are corrected. |
VS2017, TypeScriptDefinitionGenerator v1.1.24 Original C# code:
Generated TS:
|
As far as I can tell, with Visual Studio 2017 Update 2 build 26430.15, the code model is no longer reporting the wrong location - the So the workaround I proposed no longer appears to be necessary. Now that VS is behaving correctly, and you've also fixed #7 and #13 I'm no longer seeing this problem. However, I think @justdmitry has identified a new issue. I find that if I use his example C#, I have to save the C# file an extra time (triggering a 2nd code generation) to get the correct output. The first time, I see the same TS he reports. But I make a trivial change to the C# file and re-save it, I then get the expected TS:
Perhaps there is an ordering problem with nested types? Update 2017/7/31: see my later comment below - I spoke too soon. This is not in fact working for me in my real project. |
This is still an issue for me. I am using an asp.net core project (where its content is implicit). I think the problem arises in the
I refactored it to remove the isCollection check
which seems to resolve the issue I'm seeing on my side, but I'm unsure as to the isCollection check's purpose (perhaps more recent architectural changes make this obsolete?) and the ramifications of its removal. |
@mbreaton will this fix be in a new release soon? I'm getting the same problem, that all my types are |
I've realised I was premature in saying that I'm no longer seeing these problems. It turns out that in the simple class library project (using the new VS15-style |
I checked on this and I think it's not a bug, Typescript tries to analyze the list and deduct the type, if it can't, then creates a any[]. To solve this, I had to create the dependencies first and then the object, for example, create currency first (no dependency, just a number, a symbol, etc) and then create money.d.ts (that has currency on it). So, it works but needs to have all dependencies solved first. |
I'm not quite sure what you mean, @mdelgadov when you say "Typescript tries to analyze the list" - the lists in this case are all defined in C#, so how can TypeScript be trying to analyze it? The point of this extension is to extract the type definitions from C# source code and then generate TypeScript code from that. So the problem here isn't going to be anything to do with what TypeScript is doing - by the time TypeScript gets a look in, this extension has already finished its work. Moreover, this used to work with the VS2015 version of this feature (back when it was a feature of WebEssentials instead of a separate extension). So to regard this as not a bug doesn't seem appropriate, since it's a regression from how the previous version worked. (Also, TypeWriter - https://github.com/frhagn/Typewriter/releases - is able to generate suitable TypeScript definitions from C# types that involve |
Installed product versions
Description
When a property of a class is of type
List<T>
for someT
which is a) defined in the same project, and b) has already had its Generate TypeScript Definitions context menu item checked, the TypeScript property will be of typeany[]
instead of producing useful static type information.Steps to recreate
Create a project (e.g., a plain .NET Class Library, although this seems to happen in any project type I've tried, including also classic ASP.NET, ASP.NET Core, and .NET Standard class library projects), and add this in a
Child.cs
file:Right click and check Generate TypeScript Definitions
Then add this in
Parent.cs
Right click and check Generate TypeScript Definitions
Current behavior
The extension produces this TypeScript as
Parent.d.ts
:There are two problems here. The first has already been reported in #7 - the
item
property is not using theserver.child
type in the generatedChild.d.ts
file, and has instead inlined the type definition, so it does at least have the correct shape. That's obviously not the problem I'm reporting here, since there's already an open issue for that, but I mention it because it's hard to miss.The second problem here, and this is the one I'm raising this issue for, is that the
items
property has typeany[]
.Expected behavior
The
items
property should have typeserver.child[]
. Or, for as long as #7 remains open, it should at least produce an inlined array type with the correct shape.Root cause
Having single-stepped through this in the debugger, I have found that the problem occurs at https://github.com/madskristensen/TypeScriptDefinitionGenerator/blob/master/src/Generator/IntellisenseParser.cs#L287 in
IntellisenseParser.TryToGuessGenericArgument
. This code correctly determines the full name of the relevant type, and passes that toprojCodeModel.CodeTypeFromFullName
. But unfortunately, this returns aCodeType
whoseInfoLocation
returnsvsCMInfoLocationExternal
even though the type in question is in fact defined in the same project.This seems like it might be a Visual Studio 2017 bug. (I'm asking a friend on the VSIP program if he can find anything out about this.) Or possibly this is not the best way to obtain a
CodeType
for a type in the same project.The text was updated successfully, but these errors were encountered: