forked from MapComplete/MapComplete
Typing: make 'and' and 'or' in TagsFilter readonly
This commit is contained in:
parent
c97c2c0efd
commit
eeea443de6
2 changed files with 12 additions and 12 deletions
|
@ -9,23 +9,23 @@ import ComparingTag from "./ComparingTag"
|
|||
import { FlatTag, OptimizedTag, TagsFilterClosed, TagTypes } from "./TagTypes"
|
||||
|
||||
export class And extends TagsFilter {
|
||||
public and: TagsFilter[]
|
||||
public and: ReadonlyArray<TagsFilter>
|
||||
|
||||
constructor(and: TagsFilter[]) {
|
||||
constructor(and: ReadonlyArray<TagsFilter>) {
|
||||
super()
|
||||
this.and = and
|
||||
}
|
||||
|
||||
public static construct(and: TagsFilter[]): TagsFilter
|
||||
public static construct(and: (FlatTag | (Or & OptimizedTag))[]): TagsFilterClosed & OptimizedTag
|
||||
public static construct(and: TagsFilter[]): TagsFilter {
|
||||
public static construct(and: ReadonlyArray<TagsFilter>): TagsFilter
|
||||
public static construct(and: ReadonlyArray<(FlatTag | (Or & OptimizedTag))>): TagsFilterClosed & OptimizedTag
|
||||
public static construct(and: ReadonlyArray< TagsFilter>): TagsFilter {
|
||||
if (and.length === 1) {
|
||||
return and[0]
|
||||
}
|
||||
return new And(and)
|
||||
}
|
||||
|
||||
private static combine(filter: string, choices: string[]): string[] {
|
||||
private static combine(filter: string, choices: ReadonlyArray< string>): string[] {
|
||||
const values = []
|
||||
for (const or of choices) {
|
||||
values.push(filter + or)
|
||||
|
@ -443,7 +443,7 @@ export class And extends TagsFilter {
|
|||
if (containedOrs.length === 1) {
|
||||
newAnds.push(containedOrs[0])
|
||||
} else if (containedOrs.length > 1) {
|
||||
let commonValues: TagsFilter[] = containedOrs[0].or
|
||||
let commonValues: TagsFilter[] = [...(containedOrs[0].or)]
|
||||
for (let i = 1; i < containedOrs.length && commonValues.length > 0; i++) {
|
||||
const containedOr = containedOrs[i]
|
||||
commonValues = commonValues.filter((cv) =>
|
||||
|
|
|
@ -10,17 +10,17 @@ import ComparingTag from "./ComparingTag"
|
|||
import { FlatTag, OptimizedTag, TagsFilterClosed, TagTypes } from "./TagTypes"
|
||||
|
||||
export class Or extends TagsFilter {
|
||||
public or: TagsFilter[]
|
||||
public or: ReadonlyArray<TagsFilter>
|
||||
|
||||
constructor(or: TagsFilter[]) {
|
||||
constructor(or: ReadonlyArray<TagsFilter>) {
|
||||
super()
|
||||
this.or = or
|
||||
}
|
||||
|
||||
public static construct(or: TagsFilter[]): TagsFilter
|
||||
public static construct(or: ReadonlyArray<TagsFilter>): TagsFilter
|
||||
public static construct<T extends TagsFilter>(or: [T]): T
|
||||
public static construct(or: ((And & OptimizedTag) | FlatTag)[]): TagsFilterClosed & OptimizedTag
|
||||
public static construct(or: TagsFilter[]): TagsFilter {
|
||||
public static construct(or: ReadonlyArray<TagsFilter>): TagsFilter {
|
||||
if (or.length === 1) {
|
||||
return or[0]
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ export class Or extends TagsFilter {
|
|||
if (containedAnds.length === 1) {
|
||||
newOrs.push(containedAnds[0])
|
||||
} else if (containedAnds.length > 1) {
|
||||
let commonValues: TagsFilter[] = containedAnds[0].and
|
||||
let commonValues: TagsFilter[] = [...(containedAnds[0].and)]
|
||||
for (let i = 1; i < containedAnds.length && commonValues.length > 0; i++) {
|
||||
const containedAnd = containedAnds[i]
|
||||
commonValues = commonValues.filter((cv) =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue