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

Can not compile ts due to error with getter method #96

Closed
Johannes-Vitt opened this issue Dec 22, 2021 · 5 comments
Closed

Can not compile ts due to error with getter method #96

Johannes-Vitt opened this issue Dec 22, 2021 · 5 comments

Comments

@Johannes-Vitt
Copy link

I'm using node 17.0.1 with typescript version 4.4.4. and I can no longer run my project after I include the import statement for the library.

import { PKPass } from 'passkit-generator';

I went into the node_modules folder of my project and had a look directly into the code of PKPass.d.ts. My IDE showed the following error on line 124 in the getter method for the type:

The return type of a 'get' accessor must be assignable to its 'set' accessor type Type 'undefined' is not assignable to type 'PassTypesProps'.

After having removed | undefined from this line, the project was running again. However I am trying to use the library in a docker container where I can not manipulate the node_modules directly, so this is not a fix for me. Is there some typescript setting I'm missing? How else can I avoid this error?

@Johannes-Vitt Johannes-Vitt changed the title Can not compile ts due to error Can not compile ts due to error with getter method Dec 22, 2021
@alexandercerutti
Copy link
Owner

Hey there, @Johannes-Vitt, thanks for using passkit-generator!

I never met this error you reported me. Also I never used seriously Docker, so I hope I can be helpful.
Are you perhaps using a sort of strict mode? Would you mind to share your tsconfig.json? So I can try with the examples code.

Also, do you mind report Typescript the error code along with the message? So I can do better searches. Until now, I was able to find this proposal: microsoft/TypeScript#43662, but I don't know if that is strictly related.

Anyway, what's weird is that type getter / setter 's types are by design: you must set a valid type but you might get undefined by type getter if you didn't set one before.

Let me know!

@Johannes-Vitt
Copy link
Author

Johannes-Vitt commented Dec 22, 2021

@alexandercerutti Thank you for the quick reply! I also encounter this error when running on my host system instead of docker, so I think it is not related to Docker. I don't have too much experience with typescript, so I am not familiar with all the different settings. Maybe you can spot something that is triggering this error.

When I run tsc --build tsconfig.prod.json I get the following errors:

node_modules/passkit-generator/lib/PKPass.d.ts:123:9 - error TS2380: 'get' and 'set' accessor must have the same type.
123 set type(type: Schemas.PassTypesProps);
node_modules/passkit-generator/lib/PKPass.d.ts:124:9 - error TS2380: 'get' and 'set' accessor must have the same type.
124 get type(): Schemas.PassTypesProps | undefined;
Found 2 errors.

You can find my tsconfig.json and my tsconfig.prod.json attached:

{
  "compilerOptions": {
    "baseUrl": "./",
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "module": "commonjs",
    "outDir": "dist",
    "removeComments": true,
    "sourceMap": true,
    "strict": true,
    "target": "es6",
    "moduleResolution": "node",
    "types": [
      "node"
    ],
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "src/**/*.ts",
    "spec/**/*.ts"
, "upload_to_cloud_storage.ts"  ],
}

tsconfig.prod.json:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "sourceMap": false
  },
  "exclude": [
    "spec",
    "src/**/*.mock.ts"
  ]
}

@alexandercerutti
Copy link
Owner

@Johannes-Vitt I think it is related to strict: true. Do you mind to attempt remove it and let me know if it gets solved? I usually don't use it because it is... too strict sometimes.

Otherwise I'll check this evening (GMT+1).

@Johannes-Vitt
Copy link
Author

@alexandercerutti thank you very much! It is working now.

@alexandercerutti
Copy link
Owner

@Johannes-Vitt I'll make a review of code with strict mode enabled, but if you want to leverage strict features, I suggest you to enable single flags (at least, for me often it is enough).

Closing this meanwhile 😄

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

No branches or pull requests

2 participants