ASP Identity User outputs error

Issue #74 closed
Florian Verdonck
created an issue

I hope it was fixed with issue #47 but when adding the TsClass attribute to a class that inherits IdentityUser the output contains duplicate interface issue due to the generic nature of the IdentityUser class.

Steps to reproduce: Create class library and add nuget packages:

Install-Package  Microsoft.AspNet.Identity.EntityFramework
Install-Package TypeLite

Create the following class that inherits from IdentityUser

namespace OceanBlueTyped
    [TsClass(Module = "OceanBlue")]
    public class OceanUser : IdentityUser
        public string Color { get; set; }

this generates:

declare module OceanBlue {
    interface OceanUser extends Microsoft.AspNet.Identity.EntityFramework.IdentityUser {
        Color: string;
    interface Person {
        Id: number;
        FirstName: string;
declare module Microsoft.AspNet.Identity.EntityFramework {
    interface IdentityUser extends Microsoft.AspNet.Identity.EntityFramework.IdentityUser<string, Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin, Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole, Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim> {
    interface IdentityUser<TKey, TLogin, TRole, TClaim> {
        Email: string;
        EmailConfirmed: boolean;
        PasswordHash: string;
        SecurityStamp: string;
        PhoneNumber: string;
        PhoneNumberConfirmed: boolean;
        TwoFactorEnabled: boolean;
        LockoutEndDateUtc: Date;
        LockoutEnabled: boolean;
        AccessFailedCount: number;
        Roles: TRole[];
        Claims: TClaim[];
        Logins: TLogin[];
        Id: TKey;
        UserName: string;
    interface IdentityUserRole<TKey> {
        UserId: TKey;
        RoleId: TKey;
    interface IdentityUserClaim<TKey> {
        Id: number;
        UserId: TKey;
        ClaimType: string;
        ClaimValue: string;
    interface IdentityUserLogin<TKey> {
        LoginProvider: string;
        ProviderKey: string;
        UserId: TKey;
    interface IdentityUserRole extends Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole<string> {
    interface IdentityUserClaim extends Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim<string> {
    interface IdentityUserLogin extends Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin<string> {

You have duplicate interfaces and TypeScript can't handle this. Suggestions?

Comments (3)

  1. Simon Lovely

    Hi @Florian Verdonck

    I'm not sure there's too much that could be done for this in the general case - there are just some things that are perfectly valid in c# but not in TypeScript.

    In your specific case, you might be able to create your own "IdentityUser" base class (which would derive directly from the generic IdentityUser<XXX> class) - the MS provided one contains nothing but a couple of constructors so easy to duplicate. That way your class will be in OceanBlue namespace and won't interfere with the base class. However, it depends what bits of the identity framework you use whether that will work, and I'm afraid I can't help you out with that.

    The only other alternative might be to use a custom formatter, to modify the name of one of the generated interfaces - see "Custom Formatters" on this page: However, I can't remember if the parameters give you enough info to enable that or not. (I have a dream that one day I'll find some time to build on the customization options to do all sorts of things including generating methods that could call server WebAPI methods, but no idea if I'll ever get the time for that).

  2. Lukas Kabrt repo owner

    As Simon mentioned, there isn't much we can do on the TypeLITE side.

    The new, more flexible, formatter has been recently introduced, so I think you should be able to rename IdentityUserRole<TKey> to something like IdentityUserRoleBase<TKey> with .WithTypeFormatter

  3. Log in to comment