logo
down
shadow

Property X doesn't exist on type Y[]


Property X doesn't exist on type Y[]

By : abdo mohamed
Date : November 19 2020, 03:01 PM
may help you . You are declaring quiz property as array via Quiz[], therefore you need to access item of array to be able to access questions property.
But you probably want to redeclare the property to just Quiz...
code :
import {Quiz} from "../models/quiz";

export class ProfComponent {

  quiz = {questions: []} as Quiz;

  nextQuestion(quiz) {
    this.quiz.questions.push(quiz.questions)
  }

}
import {Quiz} from "../models/quiz";

export class ProfComponent {

  quizes = [{questions: []}] as Quiz[]; // array of Quiz objects

  nextQuestion(quiz) {
    this.quizes[0].questions.push(quiz.questions); // access the first quiz
  }

}


Share : facebook icon twitter icon
TypeScript factory pattern says property doesnt exist

TypeScript factory pattern says property doesnt exist


By : Techie
Date : March 29 2020, 07:55 AM
help you fix your problem Quick Fix
You can use type assertions to take the type checking away from TypeScript and into your own hands.
code :
var sammy = <Eagle><any>zoo.addAnimal('eagle');
sammy.fly(15)
class Zoo {
    animals:Animal[] = [];

    addAnimal(type: 'elephant'): Elephant;
    addAnimal(type: 'eagle'): Eagle;
    addAnimal(type: string): Animal;
    addAnimal(type: string): Animal {
        var a: Animal;

        switch(type) {
            case 'elephant':
                a = new Elephant();
                break;
            case 'eagle':
                a = new Eagle();
                break;
            default:
                throw new Error('Animal of type \'' + type + '\' doesn\t exist');
        }

        this.animals.push(a);
        return a;
    }
}

var zoo = new Zoo();

// No type assertion needed, sammy is an eagle!
var sammy = zoo.addAnimal('eagle');
sammy.fly(15)
Property 'list' does not exist on type 'database' and, Property 'push' does not exist on type 'AngularFireObject<any&

Property 'list' does not exist on type 'database' and, Property 'push' does not exist on type 'AngularFireObject<any&


By : Bhushan
Date : March 29 2020, 07:55 AM
To fix this issue 1) Answer for your first error
You need to use af.list() instead of af.database.list() as it does not exist in recent updates
TS2339 : Property totalPages doesnt exist on type Object

TS2339 : Property totalPages doesnt exist on type Object


By : Jim Schueler
Date : March 29 2020, 07:55 AM
this one helps. This is because Typescript compiler checks that data variable. To fix this explicitly tell TypeScript type of data as any ,
code :
this.projetSevice.getProjects(this.currentPage,this.size)
          .subscribe((data:any)=>{
Error: Property 'split' does not exist on type 'string | ArrayBuffer'. Property 'split' does not exist on type 'ArrayBuf

Error: Property 'split' does not exist on type 'string | ArrayBuffer'. Property 'split' does not exist on type 'ArrayBuf


By : Animesh Kumar
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I'm trying to convert image into Base64 by following a tutorial, when I'm uploading image from angular 6 project. when I press submit button I could able to get the output as value:"base64 code" and also I could able to get the same image by converting the code into image by using a "Convert Your Base64 to Image". But in the code, it shows "Property 'split' does not exist on type 'string | ArrayBuffer'.Property 'split' does not exist on type 'ArrayBuffer'." error by underlining split in red. I tried similar question & answers too. But it was unable to remove the error. , You have to cast the values you want to split.
code :
(<string>reader.result).split(',')[1]
error with typescript compiler: property forEach doesnt exist in type sprite_loading

error with typescript compiler: property forEach doesnt exist in type sprite_loading


By : user2149236
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further If you are leaning on an array, you can get it's definition for free. Example:
code :
interface sprite_loading extends Array<{ URL: string, name: string}> {
    [index: number]: {
        URL: string,
        name: string
    }
}

let example: sprite_loading = [
    { URL: 'foo', name: 'foo' },
    { URL: 'bar', name: 'bar' },
    { URL: 'baz', name: 'baz' }
];

example.forEach((val) => console.log(val.URL));
type Sprite = { URL: string, name: string, things: Thing[] };

let example: sprite_loading = [
    { URL: 'foo', name: 'foo' },
    { URL: 'bar', name: 'bar' },
    { URL: 'baz', name: 'baz' }
];
type Thing = { thingness: number };
type Sprite = { URL: string, name: string, things: Thing[] };

let example: Sprite[] = [
    { URL: 'foo', name: 'foo', things: [{ thingness: 5}, { thingness: 8}] },
    { URL: 'bar', name: 'bar', things: [] },
    { URL: 'baz', name: 'baz', things: [] }
];

example.forEach((val) => console.log(val.URL));
Related Posts Related Posts :
  • how do i handle POST response
  • constructor being called duplicate in *ngFor due to @ViewChild
  • Angular4 OAuth2 IdentityServer4
  • ERROR TypeError: Cannot read property 'name' of undefined
  • Angular4 http get with URL parameter
  • What is the difference between fakeAsync's tick() and done() in angular2 testing?
  • How to push in service without losing previous data?
  • How to make custom arrow mark in agm-map?
  • Upload File in Angular 4 using FormData works in Local but not on Azure App Service
  • How to automatically deploy a Laravel app with embedded Angular to Heroku
  • Unexpected module 'Ng2SmartTableModule' declared by the module 'AppModule'
  • use angular-cli project with visual studio asp.net empty web app?
  • How to load different templates for the same component?
  • Creating Angular4 'Loading' Screen: ExpressionChangedAfterItHasBeenCheckedError
  • How to pass a array value as color in Angular 4
  • Coerce the HttpResponse into an item of the specified type, complete with custom methods
  • Angular/rxjs: Why don't I have to import toPromise anymore?
  • Angular 2 @Input not works for router outlet
  • Nested Model - Angular 2
  • Supress duplicate error in aot compiler
  • Angular2 ExpressionChangedAfterItHasBeenCheckedError
  • Consuming my promise inside my Angular component
  • Despite error cannot read property length of null, the code works
  • Accessing data returned by Promise.all
  • How to add background image with ngStyle?
  • Ionic Headers Failing to set through http.post
  • Angular 4 routing/state problems
  • Angular 2 Dashboard application web api call at initialization
  • ngrx/store:subscribe works fine but async in template gives [object Object]
  • Angular2 - how to mix custom and declared arguments in constructor
  • Implementing Geolocation from @ionic-native/geolocation
  • Angular - Test library before publish
  • AoT Compilation Failed - no such file or directory, lstat 'tsconfig-aot.json'
  • Docker container from Angular4 app : "-p" : executable file not found in $PATH
  • Invalid container name
  • Angular - NgStyle fall back image
  • Angular Observable not updating when I subscribe.
  • Angular mat-checkbox getElementById
  • Angular 4 Injecting route in the APP_INITIALIZER
  • Error: EACCES: Error: EACCES: permission denied, open '/Users/emilio/.ionic/daemon.log' at Error (native)
  • selected value in dropdown list does not work Angular
  • how to smooth scroll down to element on page load angular 4?
  • AngularFire update breaks the app
  • experimentalDecorators Warning on ts lint
  • Dexie - Check if a record exists and initialize it if not present
  • How should I use BehaviorSubject class from a Service in the HTML Template of a Component in Angular 4?
  • How to make ngx-bootstrap datepicker be able to select and display only month and year?
  • What is wrong with this Angular form that makes it reset selected values in the UI unexpectedly?
  • Angular change Interface definition when I use as with promise
  • Angular 4 dynamic headers based on user type
  • Test HTTPClient Angular 4 "Expected undefined to be defined"
  • Angular 4 Animations add parameters
  • Angular 2 - forcing API return to follow interface types
  • Ionic Page with inputs super slow
  • Angular: How to subscribe to @Input changes
  • sending data from directive to component in angular4
  • Unable to populate Chartist with data from http get (Angular 4)
  • append default headers to each get/post/put/delete request via hacking the net/BaseRequestOptions
  • Is ng-bootstrap importing all the components
  • Add onclick event on svg rect using Angular Renderer2
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org