YousefED / YousefED/typescript-json-schema

Type comments bugs

Open
#73 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.3k
Forks
332
PR merge metrics
No merged PRs in 30d

Description

Already known issue
Type comments are not used, with union types
https://github.com/YousefED/typescript-json-schema/pull/64#issuecomment-255235376

Type comments are not used, when type is imported from another file

String type, null type and pattern are applied.

/**
 * @pattern \d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d{3}[+-]\d{4}
 */
export type StringDateNullable = string | null; // "1992-04-10T20:00:00.000+0000"


export interface Person {
    birthDate: StringDateNullable;
}

Only string and null types are applyed, not pattern.

import {
    StringDateNullable
} from './common.types';


export interface Person {
    birthDate: StringDateNullable;
}

Full property info

"birthDate": {
    "pattern": "\\d{4}-\\d{2}-\\d{2}T\\d{2}\\:\\d{2}\\:\\d{2}\\.\\d{3}[+-]\\d{4}",
    "type": [
        "null",
        "string"
    ]
},

Full case

// common.types.ts
/**
 * @pattern \d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d{3}[+-]\d{4}
 */
export type StringDate = string; // "1992-04-10T20:00:00.000+0000"

// person.types.ts
import {
    StringDate
} from './common.types';


export interface Person {
    birthDate: StringDate | null;
}

Expected result

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "properties": {
        "birthDate": {
            "anyOf": [
                {
                    "pattern": "\\d{4}-\\d{2}-\\d{2}T\\d{2}\\:\\d{2}\\:\\d{2}\\.\\d{3}[+-]\\d{4}",
                    "type": "string"
                },
                {
                    "type": "null"
                }
            ]
        }
    },
    "type": "object"
}

Current result

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "properties": {
        "birthDate": {
            "type": [
                "null",
                "string"
            ]
        }
    },
    "type": "object"
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TypeScript reproductions in the issue, including the union type and imported type-comment cases, and compare their expected and current JSON schemas. Trace how type comments are handled for unions and imported types, then add regression coverage showing that the pattern is preserved while the union becomes separate string and null schemas.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.