Code Monkey home page Code Monkey logo

typescriptdefinitiongenerator's Introduction

TypeScript Definition Generator

Build status

For Visual Studio 2022:
Download this extension from the Marketplace or get the CI build.

For Visual Studio 2019:
Download this extension from the Marketplace or get the CI build.


Creates and synchronizes TypeScript Definition files (d.ts) from C#/VB model classes to build strongly typed web application where the server- and client-side models are in sync. Works on all .NET project types

See the change log for changes and road map.

For Visual Studio 2015 support, install Web Essentials 2015

From C# to .d.ts file

This extension will automatically generate .d.ts files from any C#/VB file you specify. It will turn the following C# class into a TypeScript interface.

class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IEnumerable<string> Tags { get; set; }
}

Becomes this .d.ts file:

declare module server {
	interface customer {
		id: number;
		name: string;
		tags: string[];
	}
}

The generated .d.ts file can then be consumed from your own TypeScript files by referencing server.<typeName> interfaces.

Generate d.ts file from C#/VB

To generate a .d.ts file, right-click any .cs or .vb file and select Generate TypeScript Definition.

Context menu

A .d.ts file is created and nested under the parent C#/VB file.

Nested file

Every time the C#/VB file is modified and saved, the content of the .d.ts file is updated to reflect the changes.

Settings

Configure this extension from the Tools -> Options dialog.

Settings

Contribute

Check out the contribution guidelines if you want to contribute to this project.

For cloning and building this project yourself, make sure to install the Extensibility Tools 2015 extension for Visual Studio which enables some features used by this project.

License

Apache 2.0

typescriptdefinitiongenerator's People

Contributors

anttipih-predisys avatar cbke avatar csharpfiasco avatar kvart714 avatar linusnoren avatar madskristensen avatar mbreaton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typescriptdefinitiongenerator's Issues

Compatibility with web essentials 2015 broken

The Typescript definition code generation in web essential used to generate a file with this rule :
ViewModels.cs =>ViewModels.cs.d.ts we have a team that is gradually migrating to vs 2017 and the only issue we have is that this extension does not work with definitions generated with vs 2015 because it uses a different convention ViewModels.cs =>ViewModels.d.ts.
This little thing causes pain :D

Add the ability to ignore properties with ScriptIgnoreAttribute

Installed product versions

  • Visual Studio 2017
  • Version: 1.1.24

Description

Add the ability to ignore properties with ScriptIgnoreAttribute

Steps to recreate

Try to generate the ts file for the below class:

using System.Web.Script.Serialization;
namespace ConsoleApp2
{
    public class Student
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        [ScriptIgnore]
        public string FullName => $"{FirstName} {LastName}";
    }
}

you'll get this result

declare module server {
	interface student {
		firstName: string;
		lastName: string;
		fullName: string;
	}
}

or you should get this:

declare module server {
	interface student {
		firstName: string;
		lastName: string;
	}
}

Expected behavior

Any property with ScriptIgnoreAttribute should be ignored when generating the .d.ts file as it does right now with IgnoreDataMemberAttribute and JsonIgnoreAttribute

Trigger compilation on build

Installed product versions

  • Visual Studio: 2017
  • This extension 1.1.36

Description

Feature Request: Could it be possible to optionally add an msbuild task to build these type definitions at build. I have to copy the file into ~/Scripts at the moment as it breaks my tfs build.

Steps to recreate

Compile a c# file
Use typescript.msbuild nuget package for building on TFS server
compilation fails to find type definition

Option to translate "Nullable" props in C# to "optional" props in TS

Installed product versions

  • Visual Studio: 2017
  • This extension: 1.0.12

Description

Sometimes it would be nice to automatically translate nullable class properties to optional interface properties. I already have a code change that will do this, so if you like the idea I will submit a PR.

For example, translate:

public class ItemHeaderDto
{
public int? Id { get; set; }
public string Name { get; set; } //
public string Description { get; set; } //
}

interface ItemHeaderDto{
Id?: number;
Name: string;
Description: string;
}

Steps to recreate

  1. Use extension version 1.0.12 to convert optional C# class property to a typescript interface

Current behavior

Translates all attributes to required regardless of nullability in class

Expected behavior

Automatically translate "nullable" c# props to "optional" interface props

Cannot create .d.ts for derived classes

Installed product versions

  • Visual Studio: [example 2017 Community]
  • This extension: [example 1.0.16]
  • ASP.Net Core 1.1 project

Description

Cannot generate .d.ts with derived classes

Steps to recreate

  1. create file sample.cs:
    public class SampleBase
    {
    public int MyProperty { get; set; }
    }

    public class SampleImpl : SampleBase
    {
    public int MyProperty2 { get; set; }
    }

  2. generate typescript definition

Current behavior

Throws exception

Expected behavior

Generate proper .d.ts file

stepping through the code, the following line throws exception:

IntellisenseParser.cs:86
if (baseClass != null && !underProcess.Contains(baseClass) && !HasIntellisense(baseClass.ProjectItem, references))

bacuse baseClass.ProjectItem throws COM Exception:
"Error HRESULT E_FAIL has been returned from a call to a COM component."

Seems related to #6

Option to declare types in global scope (no module)

Description

I would like the option to be able to generate type declarations that are not wrapped in a module, but rather are declared in global scope.

I would use this in combination with #10 (in particular to interop with the Microsoft.ClearScript library)

Problem installing extension on VS Community Edition 2015

Installed product versions

  • Visual Studio: Community 2015 v.14.0.25431.01 Update 3
  • This extension: v.1.0.10

Description

Try to install this extension on Visual Studio Community 2015 but the VSIX install doesn't work and report an error, see log attached.

Steps to recreate

  1. Download vsix from marketplace
  2. Run it to install
  3. Installation error wirh reported log details

Current behavior

The installation fail reporting this message: The installation is not installable on any currently installed product.

Expected behavior

Is it possible to install this extension on the Community Edition or it is only available for the official Visual Studio PRO+?
I'd like to know if there are any technical reason not allowing to run it on the Community Edition, and possibly if you plan to support it in the future for the Community Edition, Thanks!

VSIXInstaller_log.txt

Anonymous field instead of interface

Installed product versions

  • Visual Studio: VS 2017 RC
  • This extension: 1.0.11

Description

When generating a class property the resultins ts is not referring to the ts generated interface referring to the class

Steps to recreate

  1. Create an Address.cs class
    public class Address 
    {
        public string  Street{ get; set; }
    }
  1. Enable TS Generation on Address.cs
  2. Create a Person.cs class
    public class Person
    {
        public string  Name { get; set; }
        public Address HomeAddress { get; set; }
    }
  1. Enable TS Generation on Person.cs

Current behavior

Address.d.ts
declare module server { interface address { street: string; } }
Person.d.ts
declare module server { interface person { name: string; homeAddress: { street: string; }; } }

Expected behavior

Address.d.ts
declare module server { interface address { street: string; } }
Person.d.ts
declare module server { interface person { name: string; homeAddress: address; } }

Properties of type List<T> result in any[] even when T defined in same project

Installed product versions

  • Visual Studio: 2017 Enterprise v15.1 (26403.7)
  • This extension: v1.0.12
  • Windows 10 Creators Update (up to date as of 2017/05/01)

Description

When a property of a class is of type List<T> for some T 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 type any[] 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:

public class Child
{
    public int NumericValue { get; set; }
    public string TextValue { get; set; }
}

Right click and check Generate TypeScript Definitions

Then add this in Parent.cs

public class Parent
{
    public Child Item { get; set; }
    public List<Child> Items { get; set; }
}

Right click and check Generate TypeScript Definitions

Current behavior

The extension produces this TypeScript as Parent.d.ts:

declare module server {
    interface parent {
	    item: {
		    numericValue: number;
		    textValue: string;
	    };
	    items: any[];
    }
}

There are two problems here. The first has already been reported in #7 - the item property is not using the server.child type in the generated Child.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 type any[].

Expected behavior

The items property should have type server.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 to projCodeModel.CodeTypeFromFullName. But unfortunately, this returns a CodeType whose InfoLocation returns vsCMInfoLocationExternal 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.

No support for Shared Project

  • Visual Studio: 2019 Preview 3.0
  • This extension: 1.2.38

I have a NET Core app 3 + ASP.NET Core 3 project (Web SDK, .exe) and a referenced Shared Project with all the web DTOs and stuff. The reason to use Shared is that for now ASP Core 3 does not support Net.Standard 2.0 Class library (have to wait until 2.1).

So, the menu item "Generate TypeScript Definition" does not appear in a Shared Project, but does in normal ones.

Interesting bit was when I moved ItemGroup block with a related nested .cs and .d.ts files from a normal .csproj into a Shared .projitems, Generator starts compiling but I read from Output windows something like:
TypeScript Definition Generator: Started
TypeScript Definition Generator: Completed
TypeScript Definition Generator: FAILED
for each to-be-compiled .cs file.
Probably it could be fixed in VSHelpers.cs files by adding a relevant Shared project type ID?...

[JsonIgnore] Property Ignored in nested Classes

Installed product versions

  • Visual Studio 2017 Community
  • Version: 1.1.24

Description

The [JsonIgnore] on an argument is ignored when the property is nested in another class

Steps to recreate

Classes:

public class Class1
{
    public Class2 Prop{ get; set; }
 }
public class Class2
{
    public int Prop { get; set; }
    [JsonIgnore]
    public int JsonIgnoreProp{ get; set; }
 }

Current behavior

The plugin generates a result which ignores the class nesting and the [JsonIgnore]

declare module server {
	interface class1 {
		prop: {
			prop: number;
			jsonIgnoreProp: number;
		};
	}
	interface class2 {
		prop: number;
	}
}

Expected behavior

The plugin should generate a interface which takes the class2 interlace and accounts for the [JsonIgnore] property (well class2 is tactfully generated correctly, so if it takes the correct type, it would be fine).

declare module server {
	interface class1 {
		prop: class2;
	}
	interface class2 {
		prop: number;
	}
}

sbyte, ushort, uint, ulong get converted to any

Installed product versions

  • Visual Studio: 16.11.1
  • This extension: 2.2.5.0

Description

sbyte, ushort, uint, ulong get converted to any. Wouldn't number make more sense since JavaScript can handle BigIntegers?

Steps to recreate

Generate TypeScript for the following class

public class MyClass
{
    public byte Byte { get; set; }
    public sbyte SByte { get; set; }
    public short Short { get; set; }
    public ushort UShort { get; set; }
    public int Int { get; set; }
    public uint UInt { get; set; }
    public long Long { get; set; }
    public ulong ULong { get; set; }
}

Current behavior

Result is

export interface MyClass {
    Byte: number;
    SByte: any;
    Short: number;
    UShort: any;
    Int: number;
    UInt: any;
    Long: number;
    ULong: any;
}

Expected behavior

export interface MyClass {
    Byte: number;
    SByte: number;
    Short: number;
    UShort: number;
    Int: number;
    UInt: number;
    Long: number;
    ULong: number;
}

Option to have module names more specific than "server"

Installed product versions

  • Visual Studio: [example 2017 Professional]
  • This extension: [example 1.0.12]

Description

First off, love this extension, thanks for making it available to the community. One question - would it be possible to allow creation of typescript modules more specific than "server"? It would be great to have this option as the number of typescript definitions increase on a project.

Steps to recreate

  1. Create typescript definition from .cs file

Current behavior

  1. Typescript module name is always "server"

Expected behavior

  1. Would be nice to have the option to create additional module names - possibly auto-generated based on project directory structure - or possibly indicated by a comment at the top of the .cs file.

Generator Error while generating subClass

Installed product versions

  • Visual Studio: VS 2017 RC
  • This extension: 1.0.11

Description

When generating a subclass the ts is not generated and an error is shown.

Steps to recreate

  1. Create a Person.cs class
    public class Person
    {
        public string  Name { get; set; }
        public int Age { get; set; }
    }
  1. Enable TS Generation on Person.cs
  2. Create an Employee class
 public class Employee : Person
    {
        public decimal Salary { get; set; }
        public string Position { get; set; }
    }
  1. (optional) build
  2. Enable TS Generation on Employee.cs

Current behavior

Person.d.ts
declare module server { interface person { name: string; age: number; } }
then
image
and no Employee.d.ts created

Expected behavior

Person.d.ts
declare module server { interface person { name: string; age: number; } }
Employee.d.ts
declare module server { interface emplyee extends person { position: string; salary: number; } }

Is it possible to Target 4.7.2 instead of 4.6?

went to update nuget packages as several are marked as RC.

Several of the updates rely on a target of 4.7.2.

If we change the target 4.7.2 will it still load on all visual studio 2017 configs?

Project Level Regeneration

Installed product versions

  • Visual Studio: Visual Studio 2017 Professional
  • This extension: 1.1.24

Description

Ability to recreate all generated files at once.

Steps to recreate

FIRST SCENARIO:
In one file create a class ClassA;
In a second file create a second class ClassB who has a property of type ClassA.
Generate the ClassB file first.
Then generate the ClassA file.
The property in ClassB will be of type any not ClassA

SECOND SCENARIO
In one file create a class ClassA;
In a second file create a second class ClassB who has a property of type ClassA.
Generate the ClassA file first.
Then generate the ClassB file.
All is good
Then change an option CamelCaseTypeNames and save the ClassB file.
The property in ClassB will be of type with a different casing then ClassA

Ideally

Changing Options or generating one file would regenerate all files. At a minimum, would be nice to be able click on the project and regenerate files.

Modifying tsdefgen.json requires reloading Visual Studio

Current behavior

Modifying project's tsdefgen.json requires reloading Visual Studio in order changes take effect.

Expected behavior

Changes take effect after saving tsdefgen.json file in Visual Studio or at least after reloading project/reopening solution.

Installed product versions

  • Visual Studio: 2022 Community
  • This extension: 1.3.53

GlobalScope=true option is not respected in navigation property types

Description

When GlobalScope option is set to True, the type definitions are generated correctly in the global scope (without a surrounding module). But if one entity references another the reference type is generated incorrectly with DefaultModuleName prefix despite GlobalScope=True:

Current behavior

	class Supplier {
        ...
        }
	class Product {
		productId: number;
                ...
		supplierId?: number;
		supplier: server.Supplier;
	}

If DefaultModuleName is an empty string, it is generated as supplier: .Supplier;

Expected behavior

	class Product {
        ...
	        supplier: Supplier;
        }

Installed product versions

  • Visual Studio: 2022 Community
  • This extension: 1.3.53

subclassed names not correct camel case form

Installed product versions

  • Visual Studio: [example 2017 Community]
  • This extension: [example 1.1.22]

Description

Following code:
public class SampleBase
{
public int MyProperty { get; set; }
}
public class SampleImpl : SampleBase
{
public int MyProperty2 { get; set; }
}

gets generated as:
declare module server {
interface sampleBase {
myProperty: number;
}
interface sampleImpl extends SampleBase {
myProperty2: number;
}
}

Steps to recreate

  1. Create test file with above snippet
  2. Generate Typescript

Current behavior

subclass name generated as SampleBase

Expected behavior

subclass name should be sampleBase

Project Level Options

Installed product versions

  • Visual Studio: 2017 Professioinal
  • This extension: 1.1.24

Description

A project level override file for options. So all team members do not need to affect their global settings to produce a consistent output for the team.

probably in JSON format.

could include output directory and project level module name.

Camel case bug when a property is of type Enum or another Class

Installed product versions

  • Visual Studio Pro 2017
  • Version: 1.1.24

Description

The extension doesn't take into consideration Camel casing when the class contains a property of type Enum or another class

Steps to recreate

Create this class:

    public class Person
    {
        public string Name { get; set; }
        public Address HomeAddress { get; set; }
        public Gender Gender { get; set; }
    }

    public enum Gender
    {
        Male,
        Female
    }

    public class Address
    {
        public string Street { get; set; }
    }

Now generate the d.ts file

Current behavior

The generated code is:

declare module server {
	interface person {
		name: string;
		homeAddress: server.Address;
		gender: server.Gender;
	}
	const enum gender {
		male,
		female,
	}
	interface address {
		street: string;
	}
}

Expected behavior

The generated code should be this:

declare module server {
	interface person {
		name: string;
		homeAddress: server.address;
		gender: server.gender;
	}
	const enum gender {
		male,
		female,
	}
	interface address {
		street: string;
	}
}

Visual Studio hangs/crashes when creating a d.ts file

Installed product versions

  • Visual Studio: 2019 Enterprise
  • This extension: 1.2.38

Description

When I tried to create TypescriptDefintiions for the first file in my Project, it worked. When I tried to repeat that step with the next file, Visual Studio stops responding and I have to kill the process of VS and restart. When I create the d.ts - file manually and change the property "Custom Tool" of the .cs file, I can generate the code successfully by saving the cs - file again.

Steps to recreate

  1. Right Click cs - File in solution explorer
  2. select "Generate TypescriptDefinition" in context menu
  3. kill Visual Studio

Current behavior

Visual Studio is hanging

Expected behavior

d.ts file gets created

Child class in parent class should be lowercase

Installed product versions

  • Visual Studio: [example 2017 15.7.4]
  • This extension: [1.1.24]

Description

Parent class uses child class name with uppercase but child class is lowercase when [NotMapped] is used. If [NotMapped] is not used then the child class is not strongly typed.

Note: Please tell me if I am just doing this the wrong way round.

Note: Currently I just change the uppercase character to lowercase and it works find until the type is regenerated, so mostly it is just annoying. But I can see on larger project where this could be problematic.

Steps to recreate

Create a class and child class and generate a typedef for the classes.

Current behavior

Case 1:

public class Child
{
public int Id { get; set; }
public int Count { get; set; }
}
public class Parent
{
public int Id { get; set; }
public Child[] Children {get;set;}
}

declare module server {
interface child {
id: number;
count: number;
}
interface parent {
id: number;
children: { // would like it to be a strongly typed array.
id: number;
count: number;
}[];
}
}

Case 2:

public class Child
{
public int Id { get; set; }
public int Count { get; set; }
}
public class Parent
{
public int Id { get; set; }
[NotMapped]
public Child[] Children {get;set;}
}
Generated code
declare module server {
interface child {
id: number;
count: number;
}
interface parent {
id: number;
children: server.Child[]; // should be lowercase to match generated child class name.
}
}

Error TS2694 (TS) Namespace 'server' has no exported member 'Child'.

Expected behavior

I think the child class name in the parent class should be lowercase, not uppercase.

No support in Vs 22

Installed product versions

  • Visual Studio: 2022 Professional
  • This extension: 1.3.53

Description

no support in vs 22

Steps to recreate

install the tool
restart vs 22

Current behavior

the option to generate .ts file is absent when right-clicking or in settings

Expected behavior

the option to generate .ts should appear

IntellisenseParser does not detect base type

Installed product versions

  • Visual Studio: 2017 RC.4+26206.0 Enterprise
  • This extension: 1.0.11

Description

When generating the TypeScript definition for a derived type, the IntellisenseParser does not detect the base type, although the definition for the base type already has been generated. The newly created definition file contains the interface for the derived and the base type.
I noticed that the IntellisenseParser is looking for ResponseModel.cs.d.ts while the GenerationService creates the file ResponseModel.d.ts.

Steps to recreate

  1. In an web application create a type named ResponseModel
  2. Generate TypeScript definition for ResponseModel.cs
  3. The file ResponseModel.d.ts is generated
  4. Create a second type named DerivedResponseModel and derive it from ResponseModel.
  5. Generate TypeScript definition for DerivedResponseModel.cs
  6. The file DerivedResponseModel.d.ts is generated

Current behavior

The file DerivedResponseModel.d.ts has the following content:

declare module server {
	interface DerivedResponseModel extends ResponseModel {
	}
	interface ResponseModel {
	}
}

Expected behavior

The file DerivedResponseModel.d.ts should have the following content:

declare module server {
	interface DerivedResponseModel extends ResponseModel {
	}
}

Problem with web essential for visual studio 2015 compatibility

Installed product versions

  • Visual Studio: [example 2019Professional]
  • This extension: [example 1.2.38]

Description

I have generate the typescript file using visual studio 2015 using the typescript generator that in inclused with web essential extensions and when i use visual studio 2019 with typescript definition generator for editing the .cs source file the extension create a new typescript file and doesn't update the existing file.
I can't use visual studio 2019 without solving this problem

Steps to recreate

  1. Create a new .cs file with visual studion 2015
  2. Use web essential extension for generate typescript definition
  3. Open the solution using visual studio 2019
  4. Edit the .cs class
  5. Save for update the typescript definition

Current behavior

The extension create a new typescript definition and if continue editing the .cs file using VS19 the extension update the new typescript definition

Expected behavior

The extension update the typescript definition generated with VS15 and i can use VS15 or VS19 without typescript definition duplicated

The custom tool 'DtsGenerator' failed.

Installed product versions

  • Visual Studio: 2017 Enterprise
  • This extension:1.0.12

Description

I tried to generate the *.d.ts file from a few of my C# classes. I received the error message "The custom tool 'DtsGenerator' failed.

Steps to recreate

  1. Right click on C# file
  2. Select "Generate TypeScript Definition"
  3. Find green line under file
  4. Hover over line to see error message.

Current behavior

No file generated. No detailed reason as to what caused DtsGenerator to fail.

Expected behavior

I would like to see why the generation failed. I would also like to see the generated file.

Sample Classes:
`
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNet.Identity;
using Newtonsoft.Json;

namespace ClaimsManager.Models.UI
{
public class WindowsAccount
{
[Required]
public string UserName { get; set; }

    [Required]
    public string Domain { get; set; }

    [JsonIgnore]
    public string WindowsUserID => $"{Domain}\\{UserName}";

    [JsonIgnore]
    public UserLoginInfo UserLogin => new UserLoginInfo("Windows", WindowsUserID);
}

}

using System;
using IdentityServer3.EntityFramework.Entities;
using Newtonsoft.Json;

namespace ClaimsManager.Models.UI.IdentityServer
{
public class WebClient : Client
{
public Uri Url => new Uri($"/clients/{this.ClientId}", UriKind.Relative);

    // I'm using conditional property serialization to prevent the collections
    // from being sent to the client.
    [JsonIgnore]
    public bool ShouldSerializeClientSecrets { get; } = false;

    [JsonIgnore]
    public bool ShouldSerializeRedirectUris { get; } = false;

    [JsonIgnore]
    public bool ShouldSerializePostLogoutRedirectUris { get; } = false;

    [JsonIgnore]
    public bool ShouldSerializeAllowedScopes { get; } = false;

    [JsonIgnore]
    public bool ShouldSerializeIdentityProviderRestrictions { get; } = false;

    [JsonIgnore]
    public bool ShouldSerializeAllowedCustomGrantTypes { get; } = false;

    [JsonIgnore]
    public bool ShouldSerializeAllowedCorsOrigins { get; } = false;
}

public class GridWebClient
{
    public int Id { get; set; }
    public bool Enabled { get; set; }
    public string ClientId { get; set; }
    public string ClientName { get; set; }
    public Uri Url => new Uri($"/clients/{this.ClientId}", UriKind.Relative);
}

}
`

Option to ignore properties

It would be nice to be able to ignore some properties from being generated. For example

public class Person
{
    public string FullName { get { return $"{FirstName} {LastName}"; } }
    public string LastName {get; set;}
    public string FirstName {get; set;}
}

I would like to ignore FullName from being generated, maybe with an Attribute.

Dts package did not load correctly

Installed product versions

  • Visual Studio: 2019 Community + 2022 Preview
  • This extension: 1.3.53

Description

Extension works fine in VS2019, but I get the following error when trying to configure options for dts in VS2022:
Dts-Error

Attached VS2022 activity log with an error description at the end of the file:
Dts-Error-VS2022-ActivityLog.log

Steps to recreate

Go to "Generate d.ts" in VS options menu.
It's possible that the issue could be caused by having VS2022-preview installed alongside VS2019?

Current behavior

Extension doesn't work.

Expected behavior

Extension should work.

Null ref errors

Hello, on some class types there are null ref errors after generating the model

New version generates "export" module instead of "declare" for PUBLIC classes, so interfaces become inaccessible.

Installed product versions

  • Visual Studio: [Microsoft Visual Studio Community 2019 Version 16.10.2 ]
  • This extension: [1.3.47]

Description

I was using generator 2 or more years. Probable Today i got new version of extension (it was set to autoupdate)
and i found that i have problem, cause it works different from previous version.
so what i have:
MVC, C# project, apart ".CS" file, PUBLIC class,
TypeScript Settings : "Generate in Global Scope" = flase, "Default Module Name": server

After i change C# class i got generated ".d.ts" file and i found that my project's ".ts" files don't see anymore imterface
from this new-generated .d.ts file. ?! it was working before.
i checked generated file:
-->
export module server {
interface MyClassA { ... }
}
<--
!! before it was little bit different:
-->
declare module server {
interface MyClassA { ... }
}
<--

==> so instead of "declare" now i see "export" => i can not access MyClassA from other .ts file now.

Ofcause i can modify generated .d.ts file by hands and replace export to declare, but ...

!! === > That happens ONLY if C# class is "PUBLIC"!
If class is not PUBLIC i got "declare" and everething works ok.

Steps to recreate

  1. Create some C# class. Set it PUBLIC.
  2. DO "Generate TypeScript Definition"
  3. open any other .ts file and try to use interface from new-generated .d.ts -> it will be "undefined"

Current behavior

=> as i described before Because of "export", module interface can not be accesssed from other .ts files as before
(may be could be used some additional import/include actions, but before it was working well)

Expected behavior

=> Should use "declare" instead of "export" as it was in previous version.

Error when generating class in global scope

Thanks for putting this tool together!

I noticed that when I set it to generate classes instead of interfaces and then set those classes to be global, it creates the class without an "export" expression. This results in the following compiler error and makes the classes more difficult to consume:

TS1046 (TS) Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.

Can you please add the word "export" before global classes?

Thanks!

Option to generate classes instead of interfaces

Installed product versions

  • Visual Studio: 2017
  • This extension: latest

Description

In order to interact with Microsoft.ClearScript library, I'd like to be able to choose to create classes instead of interfaces. Interfaces are not very useful as in this case the TypeScript should be able to 'new up' instances of the types.

How do I consume these definitions?

Installed product versions

  • Visual Studio: 2017
  • This extension: TypeScriptDefinitionGenerator 1.1.24

Description

I cannot consume the generated types. I've tried ///referenc'ing it and I've tried it with "import { server } from '../../MyType.cs.d.ts'" (here it tells me, that MyType.cs.d.ts ist not a Module!) - with no success.

If I change "declare" to "export", the import seems to work fine but I cannot use the type with server.MyType.

A short description in your ReadMe on how to consume the files would help a lot.

Does not work on Windows 7 at all

Installed product versions

  • Windows 7
  • Visual Studio: 2017 Enterprise 15.4.1
  • This extension: 1.1.24

Description

After installing an extension in Visual Studio 2017 running on Windows 7, it simply does not work or even have a presence in Visual Studio. The right click menu option does not appear, in tools->options->text editor->javascript/typescript no new 'generate d.ts' option appears. If you make a change to any .cs files that previously had .d.ts generated (originally generated with VS 2015 with web essentials) it causes a null reference exception.

Official Error:

An exception has been encountered. This may be caused by an extension. You can get more information by examining the file 'C:\Users<username>\AppData\Roaming\Microsoft\VisualStudio\15.0_123e5413\ActivityLog.xml'

Steps to recreate

  1. Install Extension in Visual Studio running on Windows 7 machine
  2. Try to use extension in any way.
  3. Pow! No Dice! It's busted.

Current behavior

It doesn't work at all - The right click menu option does not appear, in tools->options->text editor->javascript/typescript no new 'generate d.ts' option appears. If you make a change to any .cs files that previously had .d.ts generated (originally generated with VS 2015 with web essentials) it causes a null reference exception.

Expected behavior

It should be doing what is outlined here: https://github.com/madskristensen/TypeScriptDefinitionGenerator or labeled as ONLY WORKS FOR WINDOWS 10.

I verified this by installing the extension in Visual Studio 2017 15.4.2 on Windows 10 and it worked flawlessly. I'm assuming it's Windows 7 thing, but just due diligence here.

Thanks!

Inheritance not working

Installed product versions

  • Visual Studio: [example 2017 Professional]
  • This extension: [example 1.1.21]

Description

Replace this text with a short description
Generating a model with an inheritance doesn't work

Steps to recreate

public class Foo {
  public string FooProp { get; set; }
}
public class Bar : Foo{
  public string BarProp { get; set; }
}

Generate .d.ts files for both classes

Current behavior

Bar.d.ts is created as

declare module server {
	interface bar extends Foo {
		barProp: string;
	}
}

(Foo is not recogniced!)

Expected behavior

Bar.d.ts is created correct

declare module server {
	interface bar extends server.foo {
		barProp: string;
	}
}

Should be disabled by default

Installed product versions

  • Visual Studio: 2017 Community
  • This extension: Latest version was installed by the Web Extension Pack 2017

Description

Every time I change a class, I am getting a .ts file created automatically. Since I did not manually install this add-on, I did not expect this behavior. I recommend you remove this tool from your Web Extension pack until make the following changes:

  1. Don't generate anything by default
  2. Allow developer to enable either manually via right click context menu on a class or right click to enble for folder.

Steps to recreate

  1. Create or modify a class in Visual Studio 2017

Current behavior

Generates a .ts file for all class files even controllers.

Expected behavior

Only generate .ts files for the files or directories a developer specifies.

Fails silently

Installed product versions

  • Visual Studio: [example 2017 Enterprise]
  • This extension: [example 1.0.12]

Description

Upon .cs file save, the extension files silently, the file is not generated and i can't understand why.

Steps to recreate

I do not know what am i doing wrong since i have no error output, but just try to generate something like a class with subclass and it will manifest itself.

Current behavior

It fails silently

Expected behavior

At least report what pattern is not supported that causes the failure....

DependentUpon not always set successfully in new-style MSBuild projects

Installed product versions

  • Visual Studio: 2017 Enterprise v15.1 (26403.7)
  • This extension: v1.0.12
  • Windows 10 Creators Update (up to date as of 2017/05/01)

Description

When generating the typescript file, the extension attempts to arrange for Solution Explorer to show the generated file nested inside the .cs file from which it was generated, by setting the generated file to be DependentUpon the .cs file. This intermittently fails when working with projects that use the new-style MSBuild templates introduced with Visual Studio 2017.

Steps to recreate

  1. Create a new project with the Class Library (.NET Standard) template. (ASP.NET Core Web Application (.NET Framework) also produces same issue)
  2. Add a Models folder
  3. Create a class called Child with two properties: public int NumericValue { get; set; } and public string TextValue { get; set; } (simpler probably works, but this is what my repro does)
  4. Right click on the project item and select Generate TypeScript Definition

NOTE: I cannot get this to repro if I'm debugging the Visual Studio instance. I was trying to work out why this problem was occurring before reporting it: I downloaded a copy of the source, built it, and configured VS to launch another instance of VS in the Exp hive. But I find that with the debugger attached, this problem tends not to repro. There's presumably some sort of race around when the operation kicked off by Dispatcher.CurrentDispatcher.BeginInvoke in GenerationService.CreateDtsFile gets around to executing, and attaching the debugger changes the order of events.

Current behavior

Sometimes the generated file will appear as its own separate project item, instead of being nested inside the corresponding .cs item. Sometimes you can 'fix' this by making a meaningless edit to the .cs file and saving it again, at which point the generated TypeScript file will sometimes (but not always) change into a child of the .cs file.

Expected behavior

The generated file should always always appear as a child of the corresponding .cs file after you first enable generation, instead of randomly sometimes not doing this.

Comments

The fact that you needed to defer execution through CurrentDispatcher.BeginInvoke presumably means you need to wait for the project system to catch up with the addition of the generated file. It looks to me like deferring until the dispatcher gets to DispatcherPriority.ApplicationIdle is not enough - it can take longer than that for it to work. I tried modifying the relevant code to work like this:

DispatcherTimer dt = null;
dt = new DispatcherTimer(
    TimeSpan.FromMilliseconds(100),
    DispatcherPriority.ApplicationIdle,
    (s, e) =>
    {
        var dtsItem = VSHelpers.GetProjectItem(dtsFile);

        if (dtsItem != null)
        {
            dtsItem.Properties.Item("DependentUpon").Value = sourceItem.Name;
            dt.Stop();
            Telemetry.TrackOperation("FileGenerated");
        }
    },
    Dispatcher.CurrentDispatcher);
dt.Start();

That seems to work for me. I don't much like this - polling seems like an unsatisfactory solution. Perhaps VS's extension APIs provide some better way to be notified of when project items update, or transition into some sort of 'ready' or 'available' state. But in any case, this supports my hypothesis that the problem I'm seeing occurs because this extension sometimes attempts to set up the DependentUpon relationship before VS is ready.

Namespace for class within a class

Installed product versions

  • Visual Studio: 2017 Professional
  • Extension: snys98/TypeScriptDefinitionGenerator 2.2.0.97

Description

Class within a class has wrong namespace. Causing me lots of conflicts.

Steps to recreate

Try generate the following:

namespace Company.Areas.Blah.Dtc
{
    public class SomeDtc
    {
        public int? PageNumber { get; set; }
        public IList<Row> Rows { get; set; }
        
        public class Row

Results in:

declare module Company.Areas.Blah.Dtc {
	interface Row {

Current behavior

Ends up with a Row in the wrong namespace that can conflict with other Dtcs that also have a scoped class of Row.

Expected behavior

declare module Company.Areas.Blah.Dtc.SomeDtc {
	interface Row {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.