Skip to content

type properties are not parsed #123

Description

@d9k

script

import { TypescriptParser } from 'typescript-parser';

const json = (data: any): string => JSON.stringify(data, null, '  ');

async function main() {
    const timerToPreventFreeze = setTimeout(() => {}, 999999);
    const parser = new TypescriptParser();
    console.log('# interface');
    console.log();
    console.log(json(await parser.parseSource(`
        interface A {
            n: number;
            s: string;
        }
    `)));
    console.log();
    console.log('# type');
    console.log();
    console.log(json(await parser.parseSource(`
        type A = {
            n: number;
            s: string;
        }
    `)));
    clearTimeout(timerToPreventFreeze);
  }

  main().then(() => {
    process.exit()
  });

Result

# interface

{
  "filePath": "inline.tsx",
  "rootPath": "/",
  "start": 9,
  "end": 83,
  "imports": [],
  "exports": [],
  "declarations": [
    {
      "name": "A",
      "isExported": false,
      "start": 9,
      "end": 78,
      "accessors": [],
      "properties": [
        {
          "name": "n",
          "visibility": 2,
          "type": "number",
          "isOptional": false,
          "isStatic": false,
          "start": 35,
          "end": 45
        },
        {
          "name": "s",
          "visibility": 2,
          "type": "string",
          "isOptional": false,
          "isStatic": false,
          "start": 58,
          "end": 68
        }
      ],
      "methods": []
    }
  ],
  "resources": [],
  "usages": [
    "n",
    "s"
  ]
}

# type

{
  "filePath": "inline.tsx",
  "rootPath": "/",
  "start": 9,
  "end": 80,
  "imports": [],
  "exports": [],
  "declarations": [
    {
      "name": "A",
      "isExported": false,
      "start": 9,
      "end": 75
    }
  ],
  "resources": [],
  "usages": [
    "n",
    "s"
  ]
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions