Angular 2 Component中具有未声明的数组类型的过滤器

时间:2019-06-13 12:56:49

标签: angular typescript

我的组件具有过滤未声明类型的数组的功能。

export class HomeComponent implements OnInit {
    public TaskList: []=[];
    public TaskTypes: any;

    constructor(){}

    ngOnInit() {

    this.TaskList=getTaskList();

          this.TaskTypes = [
            { test: "All Task", value: "all", class: "bg-primary", id: "all-task", icon: "fa-tasks", TaskList: this.TaskList },
            { test: "Ongoing", value: "ongoing", class: "bg-warning", id: "ongoing-task", icon: "fa-plug", TaskList: this.TaskList.filter(o => o.Status.includes("A")) },
            { test: "Hold", value: "hold", class: "bg-danger", id: "hold-task", icon: "fa-hand-paper", TaskList: this.TaskList.filter(o => o.Status.includes("H")) },
            { test: "Completed", value: "completed", class: "bg-success", id: "completed-task", icon: "fa-calendar-check", TaskList: this.TaskList.filter(o => o.Status.includes("C")) }
          ];
      }
    }

enter image description here

enter image description here

我无法为TaskList创建class.ts文件,因为TaskList的属性不是固定的,但状态'Status'是固定的。

一切正常,但编译时出现错误。

  src / app / home / home.component.ts(85,142)中的

ERROR:错误TS2339:   属性“状态”在类型“从不”上不存在。   src / app / home / home.component.ts(86,138):错误TS2339:属性   “从不”类型上不存在“状态”。   src / app / home / home.component.ts(87,158):错误TS2339:属性   “从不”类型上不存在“状态”。

哪种类型的过滤器是最好的方法?

2 个答案:

答案 0 :(得分:1)

这里:

Building base
Step 1/2 : FROM php:7-fpm-alpine
 ---> 3a7affb05baa
Step 2/2 : RUN apk add --update libzip-dev curl &&    docker-php-ext-install curl &&     apk del gcc g++ &&    rm -rf /var/cache/apk/*
 ---> Running in 017b831ba617
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/4) Installing pkgconf (1.6.0-r0)
(2/4) Installing zlib-dev (1.2.11-r1)
(3/4) Installing libzip (1.5.1-r2)
(4/4) Installing libzip-dev (1.5.1-r2)
Executing busybox-1.29.3-r10.trigger
OK: 18 MiB in 34 packages
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/24) Installing m4 (1.4.18-r1)
(2/24) Installing libbz2 (1.0.6-r6)
(3/24) Installing perl (5.26.3-r0)
(4/24) Installing autoconf (2.69-r2)
(5/24) Installing dpkg-dev (1.19.2-r0)
(6/24) Installing dpkg (1.19.2-r0)
(7/24) Installing libmagic (5.36-r0)
(8/24) Installing file (5.36-r0)
(9/24) Installing libgcc (8.3.0-r0)
(10/24) Installing libstdc++ (8.3.0-r0)
(11/24) Installing binutils (2.31.1-r2)
(12/24) Installing gmp (6.1.2-r1)
(13/24) Installing isl (0.18-r0)
(14/24) Installing libgomp (8.3.0-r0)
(15/24) Installing libatomic (8.3.0-r0)
(16/24) Installing mpfr3 (3.1.5-r1)
(17/24) Installing mpc1 (1.0.3-r1)
(18/24) Installing gcc (8.3.0-r0)
(19/24) Installing musl-dev (1.1.20-r4)
(20/24) Installing libc-dev (0.7.1-r0)
(21/24) Installing g++ (8.3.0-r0)
(22/24) Installing make (4.2.1-r2)
(23/24) Installing re2c (1.1.1-r0)
(24/24) Installing .phpize-deps (0)
Executing busybox-1.29.3-r10.trigger
OK: 218 MiB in 58 packages
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-musl
checking host system type... x86_64-pc-linux-musl
checking target system type... x86_64-pc-linux-musl
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20180731
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 1.1.1 (ok)
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking for cURL support... yes, shared
checking for pkg-config... /usr/bin/pkg-config
checking for libcurl.pc... using default path
checking for cURL 7.15.5 or greater... configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
Removing intermediate container 017b831ba617
ERROR: Service 'base' failed to build: The command '/bin/sh -c apk add --update libzip-dev curl &&    docker-php-ext-install curl &&     apk del gcc g++ &&    rm -rf /var/cache/apk/*' returned a non-zero code: 1

这就是TS的“ never类型”错误的来源。将其声明为public TaskList: []=[]; 的数组:

any

这里是有关“从不”类型的文档:

https://www.typescriptlang.org/docs/handbook/basic-types.html

答案 1 :(得分:0)

只需将“ any”添加到数组类型 公共TaskList:any [] = [];