Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when following exports? #1946

Open
WillieRuemmele opened this issue May 3, 2024 · 0 comments
Open

Error when following exports? #1946

WillieRuemmele opened this issue May 3, 2024 · 0 comments

Comments

@WillieRuemmele
Copy link

The Salesforce CLI uses this package to ensure we don't break any of our --json output, which has been super useful, but I think I've found a bug in the library, I'm not sure where it is, but I think it's related to how a package defines exports in its package.json

scenario:

we've been using this, in a node script

      const config = {
        path: file,
        skipTypeCheck: true,
        type: returnType,
      }
      return createGenerator(config).createSchema(config.type)

to generate our schemas. I've been moving types from one repo to another, these types are similar, except for a few minor differences, like changing

export type CustomField = Metadata & {
    businessOwnerGroup?: string | null | undefined;
    businessOwnerUser?: string | null | undefined;
    businessStatus?: string | null | undefined;

to

export type CustomField = Metadata & {
    businessOwnerGroup?: string;
    businessOwnerUser?: string;

so changing the type, but in a way that shouldn't matter since it's already an optional property. We then Pick a few properties off of that object for our final return type (that we use the parser to ensure remains the same) like

type SaveableCustomField = Pick<
  CustomField,
  | 'label'
  | 'description'

everything compiles in typescript, but when we run the generator on this, we get an error

Error: Invalid index "label" in type "any"
    at /Users/william.ruemmele/projects/oclif/plugin-command-snapshot/node_modules/ts-json-schema-generator/src/NodeParser/IndexedAccessTypeNodeParser.ts:77:27
    at Array.map (<anonymous>)
    at IndexedAccessTypeNodeParser.createType (/Users/william.ruemmele/projects/oclif/plugin-command-snapshot/node_modules/ts-json-schema-generator/src/NodeParser/IndexedAccessTypeNodeParser.ts:62:42)
    at ChainNodeParser.createType (/Users/william.ruemmele/projects/oclif/plugin-command-snapshot/node_modules/ts-json-schema-generator/src/ChainNodeParser.ts:35:54)
    at /Users/william.ruemmele/projects/oclif/plugin-command-snapshot/node_modules/ts-json-schema-generator/src/NodeParser/MappedTypeNodeParser.ts:112:59
    at Array.reduce (<anonymous>)
    at MappedTypeNodeParser.getProperties (/Users/william.ruemmele/projects/oclif/plugin-command-snapshot/node_modules/ts-json-schema-generator/src/NodeParser/MappedTypeNodeParser.ts:111:14)
    at MappedTypeNodeParser.createType (/Users/william.ruemmele/projects/oclif/plugin-command-snapshot/node_modules/ts-json-schema-generator/src/NodeParser/MappedTypeNodeParser.ts:42:22)
    at ChainNodeParser.createType (/Users/william.ruemmele/projects/oclif/plugin-command-snapshot/node_modules/ts-json-schema-generator/src/ChainNodeParser.ts:35:54)
    at TypeAliasNodeParser.createType (/Users/william.ruemmele/projects/oclif/plugin-command-snapshot/node_modules/ts-json-schema-generator/src/NodeParser/TypeAliasNodeParser.ts:40:43)

after lots of debugging, replacing values in node_modules, even reverting all changes and only changing the type file I haven't found a way past it.

The one thing I've found that works, is if I import from @salesforce/types/lib/metadata.js instead of @salesforce/types/metadata (this is the new package I've been moving things into)

this repo has

  "exports": {
    "./apex": "./lib/apex.js",
    "./metadata": "./lib/metadata.js",
...

where as the original (working) repo, has no exports defined

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

No branches or pull requests

2 participants