YousefED/typescript-json-schema

Upgrade to typescript v2.4 ?

mmc41 opened this issue ยท 18 comments

mmc41 commented

I noticed that the current version of typescript-json-schema is pinned to 2.1.x versions of typescript. Can it be upgraded to the new v2.2.0?

As long as the typescript team has not made significant changes to the internal APIs, this should be possible.

Actually, I looked at it for a few minutes and noticed that they removed some APIs related to js docs.

> typescript-json-schema@0.9.1 build /Users/domoritz/Developer/UW/typescript-json-schema
> tsc -p .

typescript-json-schema.ts(140,31): error TS2339: Property 'getJsDocTags' does not exist on type 'Symbol'.
typescript-json-schema.ts(141,24): error TS7006: Parameter 'doc' implicitly has an 'any' type.

I don't have time to look into it right now but it should be possible to change how we get annotations and upgrade to ts 2.2.

Just as a heads up, I was looking into the changes to the compiler for ts 2.2 and it seems that ts.Symbol.members that your code references here is now a map defined as such:

 interface Symbol {
        flags: SymbolFlags;
        name: string;
        declarations?: Declaration[];
        valueDeclaration?: Declaration;
        members?: SymbolTable;
        exports?: SymbolTable;
        globalExports?: SymbolTable;
}
type SymbolTable = Map<Symbol>;

Also, I'm a bit confused by that but MDN docs for Map seem to suggest that .length is always 0 for a map and that .size is holding what would correspond to Array.length.

So clazz.members.length === 1 might not throw any error and simply be always false.

Hope this helps you move to 2.2 ...

Edit: Typo

Thanks for the heads up @benbabic. I would have probably missed this.

The main thing I'm worried about is the changes in the API around JsDocs. I wish we could use the language service somehow instead of using compiler internal methods. However, I don't have the time to look into it at least for another month.

mmc41 commented

@domoritz Has this issue been raised with the TS team - maybe they need to know there is a need to access the JsDocs API ?

@mmc41 Kinda...
Take a look at: microsoft/TypeScript#13498

Sadly the TypeScript compiler does not support design-time decorators yet. They seem like a perfect fit for JSON Schema related annotations.

Well...

I'm using typeorm and they use reflect-metadata to extract some additional data.
So we can do fancy things like this:

import {Entity, Column, PrimaryGeneratedColumn} from "typeorm";

@Entity()
export class Photo {

    @PrimaryGeneratedColumn()
    id: number;

    @Column({
        length: 500
    })
    name: string;

    @Column("text")
    description: string;

    @Column()
    fileName: string;

    @Column("int")
    views: number;

    @Column()
    isPublished: boolean;
}

I know it will be a breaking change, but at least seems to be more "stable".
Take a look.

Can you put this in a separate issue so we can discuss it?

What about support for 'object' type which was introduced in version 2.2

mmc41 commented

FYI: In the mean time TS 2.3.1 has been released.

I just updated the title of this issue ;-)

I hope to find some time to do the upgrade soon but there are a few more pressing issues that I need to get to. I'm happy to review pull requests, though!

nfour commented

@domoritz I'd be willing to contribute a PR as this is too useful and is becoming broken by random @types/* modules being imported with object etc.

Is there any info you could share on the migration process you've already accumulated? If not I understand it's just a blind debug process.

@nfour That would be amazing! I think most of what I know is in this issue. I've also recently put a lot of effort into https://github.com/vega/typescript-to-json-schema as I was having too many problems with aliases. Maybe you find some useful things in there.

Oh, and https://astexplorer.net/ is super useful.

nfour commented

@domoritz that looks like a lot of changes, I think I'll wait until you've got that merged first ๐Ÿ‘ . I'm getting by with --ignoreErrors for now.

mmc41 commented

FYI: In the mean time TS 2.4 has been released... Updating title.

mmc41 commented

@domoritz Wonderful news! Do you plan to release a new version (npm) with this soon ?