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

7.0 causes error when used in project with typescript strict null checks #211

Closed
1 of 4 tasks
bbarry opened this issue Jan 4, 2021 · 1 comment · Fixed by #212
Closed
1 of 4 tasks

7.0 causes error when used in project with typescript strict null checks #211

bbarry opened this issue Jan 4, 2021 · 1 comment · Fixed by #212

Comments

@bbarry
Copy link
Contributor

bbarry commented Jan 4, 2021

Summary

I'm submitting a:

  • bug report
  • feature request
  • question / support request
  • other

Description

> ng build --aot --prod --subresource-integrity

√ Browser application bundle generation complete.

Error: node_modules/ng-recaptcha/recaptcha/recaptcha.component.d.ts:6:59 - error TS2344: Type '(() => void) | undefined' does not satisfy the constraint '(...args: any) => any'.
  Type 'undefined' is not assignable to type '(...args: any) => any'.

6 export declare type RecaptchaErrorParameters = Parameters<ReCaptchaV2.Parameters["error-callback"]>;
                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f17491e0d087ae9ba39cfcc961f1952016b20e75/types/grecaptcha/index.d.ts#L125 defines error callback as (): void (this is probably wrong but I am unable to find any documentation to correct it to submit the PR to DT) but the member "error-callback" is optional so its type includes undefined.

https://github.com/DethAriel/ng-recaptcha/blob/master/src/recaptcha/recaptcha.component.ts#L22-L24 uses this definition.

When the project is included in a project that builds with tsconfig:

{
  "compileOnSave": false,
  "compilerOptions": {
    "strictNullChecks": true,

the above error occurs.

To simplify:

// required grecaptcha partial type definition
namespace ReCaptchaV2 {
    export interface Parameters {
        "error-callback"?(): void;
    }
}

// line from recaptcha.component.ts
type RecaptchaErrorParameters = Parameters<ReCaptchaV2.Parameters["error-callback"]>;

https://www.typescriptlang.org/play?#code/HYQwtgpgzgDiDGEAEAlCBhEMAu8AWIAagExIDeAUEtUhAB4wD2ATtkgJbDYTMBmCyAAohm4CN2ZRyVGrIBEPZiwC08EABt1AIwQBrOQH4AFAEoAXEgBujdgBMA3DOoBfCq4rYAnjGRo1OfBAAUWYlZmFRSAkpAF4kCLFogB40TACCEgA6BKieKABtBVCVNU0deH0AXQA+eyA

open tsconfig and toggle strictNullChecks to see the error

Lib versions:

  • ng-recaptcha: 7.0.0
  • Angular: 11.0.5
  • Typescript (tsc --version): 4.1.3
bbarry added a commit to bbarry/ng-recaptcha that referenced this issue Jan 5, 2021
When an application that depends on ng-recaptcha has tsconfig.json

    "strictNullChecks": true

the `Parameters<T>` utility type fails if the type parameter allows `undefined`.

Closes DethAriel#211
DethAriel pushed a commit that referenced this issue Jan 7, 2021
When an application that depends on ng-recaptcha has tsconfig.json

    "strictNullChecks": true

the `Parameters<T>` utility type fails if the type parameter allows `undefined`.

Closes #211
@DethAriel
Copy link
Owner

Published in v7.0.1

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

Successfully merging a pull request may close this issue.

2 participants