Last active
April 19, 2018 12:06
-
-
Save rescribet/bdf043881ef0dff14cc080b51bef21ef to your computer and use it in GitHub Desktop.
Variable types don't seem to be filtered by comparing them via an array includes statement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class SomeNode { | |
public readonly termType!: string; | |
} | |
class NamedNode extends SomeNode { | |
public readonly termType: "NamedNode"; | |
constructor() { | |
super(); | |
this.termType = "NamedNode"; | |
} | |
} | |
class Literal extends SomeNode { | |
public readonly termType: "Literal"; | |
constructor() { | |
super(); | |
this.termType = "Literal"; | |
} | |
} | |
class BlankNode extends SomeNode { | |
public readonly termType: "BlankNode"; | |
constructor() { | |
super(); | |
this.termType = "BlankNode"; | |
} | |
} | |
class Collection extends SomeNode { | |
public readonly termType: "Collection"; | |
constructor() { | |
super(); | |
this.termType = "Collection"; | |
} | |
} | |
type SomeTerm = NamedNode | BlankNode | Literal | Collection | undefined; | |
function subset(x: NamedNode | BlankNode): void { | |
console.log(x); | |
} | |
function example(x: SomeTerm): void { | |
// if (!x || x.termType === "Literal" || x.termType === "Collection") does work however | |
if (!x || ["Literal", "Collection"].includes(x.termType)) { | |
return; | |
} | |
subset(x); // This should be valid | |
} | |
example(new NamedNode()); | |
example(new BlankNode()); | |
example(new Collection()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment