-
Notifications
You must be signed in to change notification settings - Fork 6k
On Upgrade to Angular 7, get a tslint error for truthiness check #8968
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
Conversation
Check these issues for a trail: microsoft/TypeScript#26262 microsoft/TypeScript@14d3c69
👍 Resolve my issue. |
Addresses: #8836 |
@roni-frantchi , since you are the creator of typescript-angular, please review. I don't see a reviewer for typescript on the technical committee |
Will the PR not create error when formParams is FormData type, for 'multipart/form-data'? Since it forces the formParams to be HttpParams or void. |
@navneetkarnani to @cbetrifork 's point, it seems like your solution holds up because TypeScript isn't smart enough (yet?) to warn you of truthiness checks in void union types. interface Foo {
yo(): number;
append(): void;
voidi(): void;
}
interface Bar {
yo(): string;
append(): boolean;
}
let union: Foo | Bar;
let foo: Foo;
const unionAsExpected = union.yo() / 10; // Error: you can't divide something that might be a string
const voidAsExpected = foo.voidi() || true; // Error: Void can't be tested for truthiness
const bummer = union.append() || true; // No error... Should have been caught? append() returns a type that's a union of void, can it be checked for truthiness? |
Specific data types ( void, HttpParams, etc ) result in better type checking, but also end up being not covering all cases at this time. Any allows working around that problem.
Changing recommendation to "any" instead of specific type to avoid having to specify all possible combinations ( and that I may not be aware of ). |
@navneetkarnani using |
Check these issues for a trail:
microsoft/TypeScript#26262
microsoft/TypeScript@14d3c69
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.3.0.0
branch for changes related to OpenAPI spec 3.0. Default:master
.Description of the PR
The Typescript 3.1 compiler (one that is used with Angular 7 onwards), has a check for void functions being checked for Truthiness. This change fixes the service function to have multiple return types if the HttpClient is being used, which is where the code gets generated.