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

[TS2.2.x] Operator '!==' cannot be applied to types #371

Closed
2 tasks done
beeman opened this issue Mar 1, 2017 · 8 comments · Fixed by #387
Closed
2 tasks done

[TS2.2.x] Operator '!==' cannot be applied to types #371

beeman opened this issue Mar 1, 2017 · 8 comments · Fixed by #387

Comments

@beeman
Copy link
Contributor

beeman commented Mar 1, 2017

What type of issue are you creating?

  • Bug

What version of this module are you using?

  • 2.1.0-rc.8.3

Please add a description for your issue:

When running the generated SDK in a project with TypeScript 2.2.1 it results in an error:

ERROR in /Users/beeman/workspace/scratch/loopback-scratch/client/src/app/shared/sdk/services/core/search.params.ts (34,42): Operator '!==' cannot be applied to types '"string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"' and '"array"'.)
/Users/beeman/workspace/scratch/loopback-scratch/client/src/app/shared/sdk/services/core/search.params.ts (37,50): Operator '===' cannot be applied to types '"string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"' and '"array"'.)

There is an example project here.

Workaround

Downgrade the Angular app to TypeScript 2.1.6.

@jmls
Copy link

jmls commented Mar 2, 2017

I think that there's some logic problem in that code anyway ...

    private _parseParam(key: string, value: any, parent: string) {
        if (typeof value !== 'object' && typeof value !== 'array') {
            return parent ? parent + '[' + key + ']=' + value
                          : key + '=' + value;
        } else if (typeof value === 'object' ||  typeof value === 'array') {
            return parent ? this._JSON2URL(value, parent + '[' + key + ']')
                          : this._JSON2URL(value, key);
        } else {
            throw new Error('Unexpected Type');
        }
    }

so, if the value is not an object and not an array, hit the first test
if it doesn't pass the first test, then it must be an array or object, so the second test is irrelevant - and this makes the last else completely redundant.

In fact, if there is an unexpected type, it's actually caught by the first test

@jmls
Copy link

jmls commented Mar 2, 2017

if you replace the _parseParam function with this code, the typescript error goes away

private _parseParam(key: string, value: any, parent: string) {
        let typeofValue:string = typeof value;

        if (typeofValue !== 'object' && typeofValue !== 'array') {
            return parent ? parent + '[' + key + ']=' + value
                          : key + '=' + value;
        } else {
            return parent ? this._JSON2URL(value, parent + '[' + key + ']')
                          : this._JSON2URL(value, key);
        }
    }

@ferares
Copy link

ferares commented Mar 8, 2017

That works, can you make a pull request, or should I?

@jmls jmls mentioned this issue Mar 9, 2017
3 tasks
@jonathan-casarrubias
Copy link
Collaborator

I will be integrating this fix as soon as the pull request points to development.

Thanks for reporting and also for fixing the issue.

lygstate added a commit to lygstate/loopback-sdk-builder that referenced this issue Mar 13, 2017
…ray' type in javascript.

And value should not be null. cause typeof null === 'object'.

Fixes for mean-expert-official#371
This was referenced Mar 13, 2017
@jonathan-casarrubias jonathan-casarrubias added this to the 2.1.0-rc.9 milestone Mar 17, 2017
jonathan-casarrubias pushed a commit that referenced this issue Mar 21, 2017
- Milestone Details: https://github.com/mean-expert-official/loopback-sdk-builder/milestone/36?closed=1

- Fix: #371
- Fix: #365
- Fix: #337
- Fix: #367
- Fix: #370
- Fix: #328
- Fix: #356
- Fix: #355
- Fix: #347
- Fix: #349
- Fix: #321
3 tasks
@Wavfact
Copy link

Wavfact commented Jun 27, 2017

This is still an issue in Typescript 2.3.4

Found this bug while researching the error message i was getting after upgrading.
6-27-2017 2-48-29 pm

@beeman
Copy link
Contributor Author

beeman commented Jun 27, 2017

@Wavfact your error seems to come from one of these files, which are not part of the SDK:

src/app/pipes/MyCurrencyPipe.ts or src/app/commercial/directives/numbers-only.directive.ts

@Wavfact
Copy link

Wavfact commented Jun 28, 2017

I downgraded to 2.1.6 as you suggested above and the issue was resolved..

In those files, there was a typescript error using typeof <var> !== "String" Thats why I posted that the issue has not been resolved yet.

@beeman
Copy link
Contributor Author

beeman commented Jun 28, 2017

If the issue is indeed in
src/app/pipes/MyCurrencyPipe.ts and src/app/commercial/directives/numbers-only.directive.ts you should just fix those files. No need to downgrade the TypeScript 2.1.6

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

Successfully merging a pull request may close this issue.

5 participants