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

[extra error] Type guard of form type of other should be filter string | number | boolean #1056

Open
Tracked by #1074
sunrabbit123 opened this issue Aug 2, 2023 · 0 comments
Labels
good first issue Good for newcomers

Comments

@sunrabbit123
Copy link
Collaborator

If strictNullCheck is true

class C {
  private p: string;
}

var strOrC: string | C;
var c: C;

// A type guard of the form typeof x === s,
// where s is a string literal with any value but 'string', 'number' or 'boolean',
//  - when true, removes the primitive types string, number, and boolean from the type of x, or
//  - when false, has no effect on the type of x.

if (typeof strOrC === "Object") {
  c = strOrC; // C
} else {
  var r2: string = strOrC; // string | C, 2322 ERROR
}

If strictNullCheck is false

class C {
  private p: string;
}

var strOrC: string | C;
var c: C;

// A type guard of the form typeof x === s,
// where s is a string literal with any value but 'string', 'number' or 'boolean',
//  - when true, removes the primitive types string, number, and boolean from the type of x, or
//  - when false, has no effect on the type of x.

if (typeof strOrC === "Object") {
  c = strOrC; // C
} else {
  var r2: string = strOrC; // string
}

releated issue

#1005 - #1005 (comment)

test case url

https://github.com/dudykr/stc/blob/main/crates/stc_ts_type_checker/tests/conformance/expressions/typeGuards/typeGuardOfFormTypeOfOther.ts

@sunrabbit123 sunrabbit123 changed the title Type guard of form type of other should be filter string | number | boolean [extra error] Type guard of form type of other should be filter string | number | boolean Aug 8, 2023
@sunrabbit123 sunrabbit123 added this to the v0.0.1: Correctness milestone Aug 14, 2023
@sunrabbit123 sunrabbit123 added the good first issue Good for newcomers label Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Development

No branches or pull requests

1 participant