Comments
noxecane
added a commit
to random-guys/siber
that referenced
this issue
Jan 12, 2020
textbook
added a commit
to textbook/starter-kit
that referenced
this issue
Apr 9, 2020
knownasilya
added a commit
to Strider-CD/strider
that referenced
this issue
May 2, 2020
Rafer45
added a commit
to Rafer45/amp-github-apps
that referenced
this issue
Jul 23, 2020
Rafer45
added a commit
to ampproject/amp-github-apps
that referenced
this issue
Jul 24, 2020
* Add json GET response for test runs in build * Add json GET response for test case history * Add page size parameter to query, limit page size * Put max page size on constant * Rename query params * Add missing express-serve-static-core type import See DefinitelyTyped/DefinitelyTyped#40138 (comment) for the reason for this import. * Make helper function for page info, simplify testRuns variable * Move db initialization to top scope * Reorder top level declarations, use pageInfo helper in buildNumber get * Fix outdated variable name * Add todos with tracking issues
abernix
added a commit
to apollographql/apollo-server
that referenced
this issue
Aug 4, 2020
The motivating factor here was to resolve the typing incompatibilities between `@types/express` and `@types/express-serve-static-core` which were caused by mis-aligned package versions. Ref: DefinitelyTyped/DefinitelyTyped#40138
Fleker
added a commit
to actions-on-google/actions-on-google-nodejs
that referenced
this issue
Aug 26, 2020
lobsterkatie
added a commit
to getsentry/sentry-javascript
that referenced
this issue
Sep 17, 2022
Recently, the issue described in DefinitelyTyped/DefinitelyTyped#40138 (wherein the `Request` and `Response` types from express claim never to have heard of standard properties like `headers`) flared up in our remix tests. It turns out the culprit was that a few days ago, DefinitelyTyped removed TS 4.0 support from a number of packages[1], among them `@types/express-serve-static-core` (upon which `@types/express` depends). Key changes in this fix: - Lock `@types/express-serve-static-core` to the last version before this change. - Add `@types/express` to `@sentry/remix`'s dev dependencies (where it should have been all along). - Update all usages of `@types/express` to latest. (Not strictly necessary, but done as part of my debugging. Doesn't seem to break anything, and we might as well be up to date.) [1] DefinitelyTyped/DefinitelyTyped#62240
Answer by Kendall Allison
This happens because when you start the application, The server is actually serving the bundles(JavaScript/CSS/HTML… output files) stored in the dist folder. Sometimes, when you make changes in your code, the changes don’t reflect in your bundles, which will lead to the server still using the old bundles. ,It usually happens when you develop Angular applications. To solve this just shut down the server & start it again:,
This behavior is also happening with ionic 4 CLI. So if a service is missing it’s members restart ionic serve will help.
– Dave Gööck
Feb 12 ’19 at 14:10
It usually happens when you develop Angular applications. To solve this just shut down the server & start it again:
$ ng serve
Answer by Alexis Novak
This happens because when you start the application, The server is actually serving the bundles(JavaScript/CSS/HTML… output files) stored in the dist folder. Sometimes, when you make…,It usually happens when you develop Angular applications. To solve this just shut down the server & start it again:,Built on Forem — the open source software that powers DEV and other inclusive communities.
It usually happens when you develop Angular applications. To solve this just shut down the server & start it again:
$ ng serve
Answer by Celine Manning
So what is going here? We have defined an empty object first and then tried to assign it the name property. This is just plain Javascript code, and Typescript should allow us to write that transparently. So why the error message?,If you enjoyed this post, have also a look also at other popular posts that you might find interesting:,We are going to understand it by providing another example, have a look at this and try to guess if it compiles, and if not what is the error message:
If we are not familiar with how the Typescript Type system works, we might be surprised to realize that this actually does not compile. So why is that? Let’s have a look at the error message we get:
Error:(54, 6) TS2339:Property 'name' does not exist on type '{}'.
If we hover over the user variable, we can see the inferred type. In Webstorm, if we click the variable and hit Ctrl+Shift+P, we get the following inferred type:
type: {}
Again it might be a bit surprising that this code does not compile. Here is the error message:
Error:(59, 8) TS2339:Property 'lessonCount' does not exist on type '{ name: string; }'.
And if we check what is the inferred type of the variable course, we get this type:
type: {name:string}
But the line course = named
does not compile, and we get the following error:
Error:(73, 1) TS2322:Type 'Named' is not assignable to type 'Course'. Property 'lessonCount' is missing in type 'Named'.
Answer by Kamari Kelly
I know I can fix the error by declaring the variable.,When compiled/transpiled through TypeScript it generates error TS2339: Property ‘myclassvar’ does not exist on type ‘MyClass’.,Can it surely be a duplicate of the ticket called «Allow declaring class members within a constructor»?
class MyClass {
constructor(){
this.myclassvar = 'abc';
}
}
Answer by Cooper Guerrero
While I was trying the below example – Passing recipe data with property binding I got the following error.,For example, to pass recipe data with property binding and use ngFor loop refer below section.,When I was trying to pass component data with property binding, I got the following typescript error : Property does not exist on value of type. This tutorial guides you how to resolve this error and also guides on how to pass recipe data with property binding.
While I was trying the below example – Passing recipe data with property binding I got the following error.
Angular is running in the development mode. Call enableProdMode() to enable the production mode.
client:52 [WDS] Live Reloading enabled.
client:150 [WDS] Errors while compiling. Reload prevented.
errors @ client:150
client:159 src/app/recipes/recipe-list/recipe-item/recipe-item.component.html:5:26 - error TS2339: Property 'recipes' does not exist on type 'RecipeItemComponent'.
5 *ngFor="let recipe of recipes">
~~~~~~~
src/app/recipes/recipe-list/recipe-item/recipe-item.component.ts:5:16
5 templateUrl: './recipe-item.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component RecipeItemComponent.
Note, the parent-child relationship for the below example is as follows.
--recipes
---- recipe.model.ts
---- recipe-detail
---- recipe-list
------ recipe-item
recipes/recipe-list/recipe-item/recipe-item.component.html
<a href="#"
class="list-group-item clearfix">
<div class="pull-left">
<h4 class="list-group-item-heading">{{ recipe.name }}</h4>
<p class="list-group-item-text">{{ recipe.description }}</p>
</div>
<span class="pull-right">
<img
[src] = "recipe.imagePath"
alt="{{ recipe.name }}"
class="img-responsive"
style="max-height: 50px;">
</span>
</a>
recipes/recipe-list/recipe-item/recipe-item.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-recipe-item',
templateUrl: './recipe-item.component.html',
styleUrls: ['./recipe-item.component.css']
})
export class RecipeItemComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
For example, to pass recipe data with property binding and use ngFor loop refer below section.
<div class="row">
<div class="col-xs-12">
<div class="pull-left">
<h3>My Recipe List</h3>
</div>
</div>
</div>
<hr>
<div class="row">
<div class="col-xs-12">
<app-recipe-item
*ngFor="let recipe of recipes"
[recipe] = "recipe"></app-recipe-item>
</div>
</div>
<hr>
<div class="row">
<div class="col-xs-12">
<div class="pull-right">
<button class="btn btn-success">Add Recipe</button>
</div>
</div>
</div>
recipes/recipe-list/recipe-list.component.ts
import { Component, OnInit } from '@angular/core';
import { Recipe } from '../recipe.model';
@Component({
selector: 'app-recipe-list',
templateUrl: './recipe-list.component.html',
styleUrls: ['./recipe-list.component.css']
})
export class RecipeListComponent implements OnInit {
recipes: Recipe[] = [
new Recipe('Recipe 1', 'This is our first recipe', 'https://lilluna.com/wp-content/uploads/2017/10/spanish-rice-resize-6.jpg'),
new Recipe('Recipe 2', 'This is our second recipe', 'https://food.fnr.sndimg.com/content/dam/images/food/fullset/2020/07/14/0/FNK_20-Minute-Sausage-And-Pepper-Ravioli-Skillet_H_s4x3.jpg.rend.hgtvcom.441.331.suffix/1594757098344.jpeg'),
new Recipe('Recipe 3', 'This is our third recipe', 'https://images.squarespace-cdn.com/content/v1/5c089f01f93fd410a92e642a/1589512502567-CNOAIL05BVT1TI0422P2/ke17ZwdGBToddI8pDm48kLkXF2pIyv_F2eUT9F60jBl7gQa3H78H3Y0txjaiv_0fDoOvxcdMmMKkDsyUqMSsMWxHk725yiiHCCLfrh8O1z4YTzHvnKhyp6Da-NYroOW3ZGjoBKy3azqku80C789l0iyqMbMesKd95J-X4EagrgU9L3Sa3U8cogeb0tjXbfawd0urKshkc5MgdBeJmALQKw/pheasant+back+burger+recipe.jpeg'),
new Recipe('Recipe 4', 'This is our fourth recipe', 'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQunf0MIpWZn3rjR-mo4u9_HKsL0Ud3SV8WTQ&usqp=CAU'),
new Recipe('Recipe 5', 'This is our fifth recipe', 'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQ_9l39e7G5y_ENz6hL6l5KhaJuroOrbzqs0Q&usqp=CAU')
];
constructor() { }
ngOnInit(): void {
}
}
recipes/recipe.model.ts
export class Recipe {
public name : string;
public description : string;
public imagePath : string;
constructor(name : string, description : string, imagePath : string){
this.name = name;
this.description = description;
this.imagePath = imagePath;
}
}
I figured out the reason why I was getting error Property ‘recipes’ does not exist on type ‘RecipeItemComponent’. I forgot to add the following statement in the RecipeItemComponent class.
@Input() recipe: Recipe;
recipe-item.component.ts
import { Component, Input, OnInit } from '@angular/core';
import { Recipe } from '../../recipe.model';
@Component({
selector: 'app-recipe-item',
templateUrl: './recipe-item.component.html',
styleUrls: ['./recipe-item.component.css']
})
export class RecipeItemComponent implements OnInit {
@Input() recipe: Recipe;
constructor() { }
ngOnInit(): void {
}
}
Answer by Lincoln Giles
Property value does not exist on type EventTarget Example,Property ‘value’ does not exist on type ‘EventTarget’ Error is a common error in Angular. It shows up when you try to access the value property of an HTML element during event binding.,The solution is to cast the event.target to appropriate HTML element as shown below
This error is flagged by the TypeScript compiler.
The $event
in both examples are of type HTMLElement
. It can represent any HTML Element. Hence the value
property is not guaranteed to exist in the $event.target
.
$event
This error is flagged by the TypeScript compiler.
The $event
in both examples are of type HTMLElement
. It can represent any HTML Element. Hence the value
property is not guaranteed to exist in the $event.target
.
HTMLElement
This error is flagged by the TypeScript compiler.
The $event
in both examples are of type HTMLElement
. It can represent any HTML Element. Hence the value
property is not guaranteed to exist in the $event.target
.
value
This error is flagged by the TypeScript compiler.
The $event
in both examples are of type HTMLElement
. It can represent any HTML Element. Hence the value
property is not guaranteed to exist in the $event.target
.
$event.target
Answer by Harvey Brady
import { of } from 'rxjs';
Answer by Wayne Moody
The EventTarget type does not inherit from the Element type which is why TypeScript fails to recognize properties such as id, class, etc. that we would expect to exist on a typical Element object.,
Without setting the proper type for the event target, we’ll get the «Property ‘value’ does not exist on type ‘EventTarget'» error while trying to get the value property of the input element. Therefore, as discussed earlier, we need to assert the type we expect the event target to be like in the following way for example:
,
Alternatively, we can also do the following if we only need to use the target property from the event:
Let’s suppose we have the following HTML element:
<div id="foo"></div>
With the following code snippet we will receive the element above as an event target in our event listener:
const elem = document.getElementById('foo');
elem.addEventListener('test', function (e) {
// Property 'id' does not exist on type 'EventTarget'.
console.log(e.target.id); // 'foo'
}, false);
elem.dispatchEvent(new Event('test'));
To make TypeScript understand the correct type for the event target, we can specify it like so:
const elem = document.getElementById('foo');
elem.addEventListener('test', function (e) {
const target = e.target as Element;
console.log(target.id); // 'foo'
}, false);
elem.dispatchEvent(new Event('test'));
We can also inline it like so:
(e.target as Element).id
Alternatively, we can also do the following if we only need to use the target
property from the event:
const elem = document.getElementById('foo');
elem.addEventListener('test', function (e: { target: Element }) {
console.log(e.target.id); // 'foo'
// Property 'type' does not exist on type '{ target: HTMLInputElement; }'.
console.log(e.type);
}, false);
elem.dispatchEvent(new Event('test'));
As it is evident from the example above, after specifying the correct type for e.target
it works fine. However, other properties (such as e.type
, etc.) would throw a TypeScript error. If we need to access those other properties of the event as well, we could do so in the following way:
const elem = document.getElementById('foo');
elem.addEventListener('test', function (e: Event & { target: Element }) {
console.log(e.target.id); // 'foo'
// other Event object properties are recognized too now:
console.log(e.type); // 'test'
}, false);
elem.dispatchEvent(new Event('test'));
We can, of course, get more specific with the type of the target events. For example, let’s suppose we wanted to get the value
attribute of the following target input
element:
<input id="foo" type="text" value="bar" />
Without setting the proper type for the event target, we’ll get the «Property 'value' does not exist on type 'EventTarget'
» error while trying to get the value
property of the input
element. Therefore, as discussed earlier, we need to assert the type we expect the event target to be like in the following way for example:
const elem = document.getElementById('foo');
elem.addEventListener('test', function (e) {
console.log((e.target as HTMLInputElement).value); // 'bar'
}, false);
elem.dispatchEvent(new Event('test'));
Assuming that the event target is <input type="file">
, we can fix this error like so:
// Property 'files' does not exist on type 'EventTarget'.
e.target.files;
// possible fix:
(e.target as HTMLInputElement).files;
Assuming that the event target is an HTML audio
/video
element, we can fix this error like so:
// Property 'controls' does not exist on type 'EventTarget'.
e.target.controls;
// possible fixes:
(e.target as HTMLMediaElement).controls;
(e.target as HTMLVideoElement).controls;
(e.target as HTMLAudioElement).controls;
Here, using the HTMLMediaElement
should be sufficient. However, we can also do the following when the target element can be either an audio
or a video
element:
type MediaType = HTMLVideoElement | HTMLAudioElement;
(e.target as MediaType).form;
Assuming that the event target is an HTML input
element, we can fix this error like so:
// Property 'form' does not exist on type 'EventTarget'.
e.target.form;
// possible fix:
(e.target as HTMLInputElement).form;
Assuming that the event target is an HTML textarea
element, we can fix this error like so:
// Property 'form' does not exist on type 'EventTarget'.
e.target.form;
// possible fix:
(e.target as HTMLTextAreaElement).form;
If the target element can be either an input
or a textarea
element, we can create a new intersection type like so:
// Property 'form' does not exist on type 'EventTarget'.
e.target.form;
// possible fix:
type InputType = HTMLInputElement | HTMLTextAreaElement;
(e.target as InputType).form;
Assuming that the event target is an HTML <input type="radio">
or <input type="checkbox">
element, we can fix this error like so:
// Property 'checked' does not exist on type 'EventTarget'.
e.target.checked;
// possible fix:
(e.target as HTMLInputElement).checked;
Assuming that the event target is an HTML <img>
element, we can fix this error like so:
// Property 'src' does not exist on type 'EventTarget'.
e.target.src;
// possible fix:
(e.target as HTMLImageElement).src;
Assuming that the event target is an HTML <source>
element, we can fix this error like so:
// Property 'src' does not exist on type 'EventTarget'.
e.target.src;
// possible fix:
(e.target as HTMLSourceElement).src;
The classList
property exists on every HTML element, so we could use Element
, HTMLElement
or a more specific type (for e.g. HTMLInputElement
, etc.). For example:
// Property 'classList' does not exist on type 'EventTarget'.
e.target.classList;
// possible fixes:
(e.target as Element).classList;
(e.target as HTMLElement).classList;
// etc.
The parentNode
property exists on every HTML element, so we could use Element
, HTMLElement
or a more specific type (for e.g. HTMLInputElement
, etc.). For example:
// Property 'parentNode' does not exist on type 'EventTarget'.
e.target.parentNode;
// possible fixes:
(e.target as Element).parentNode;
(e.target as HTMLElement).parentNode;
// etc.
The blog will help about How to Fix the “Property does not exist on type {}” Error in TypeScript & learn how to solve different problems that come from coding errors. If you get stuck or have questions at any point,simply comment below.
Question: What is the best way to approach this problem? Answer: Check out this blog code to learn how to fix errors How to Fix the “Property does not exist on type {}” Error in TypeScript. Question: “What should you do if you run into code errors?” Answer:”You can find a solution by following this blog.
Assigning properties to JavaScript objects is quite simple.
let obj = {}
obj.key1 = 1;
obj['key2'] = 'dog';
This would give me these values for obj
:
obj: {
key1: 1,
key2: 'dog'
}
The Problem
When we head over to TypeScript, running this code gives us the error below.
let obj = {}
obj.key1 = 1;
Property 'key1' does not exist on type '{}'.
How do we work with JSON objects in TypeScript?
Solution 1: The Quick Fix
In TypeScript, we can type a function by specifying the parameter types and return types.
Similarly, we need to type our objects, so that TypeScript knows what is and isn’t allowed for our keys and values.
Quick and dirty. A quick and dirty way of doing this is to assign the object to type any
. This type is generally used for dynamic content of which we may not know the specific type. Essentially, we are opting out of type checking that variable.
let obj: any = {}
obj.key1 = 1;
obj['key2'] = 'dog';
But then, what’s the point of casting everything to type any
just to use it? Doesn’t that defeat the purpose of using TypeScript?
Well, that’s why there’s the proper fix.
Solution 2: The Proper Fix
Consistency is key. In order to stay consistent with the TypeScript standard, we can define an interface that allows keys of type string
and values of type any
.
interface ExampleObject {
[key: string]: any
}
let obj: ExampleObject = {};
obj.key1 = 1;
obj['key2'] = 'dog';
What if this interface is only used once? We can make our code a little more concise with the following:
let obj: {[k: string]: any} = {};
obj.key1 = 1;
obj['key2'] = 'dog';
Solution 3: The JavaScript Fix
Pure JavaScript. What if we don’t want to worry about types? Well, don’t use TypeScript 😉
Or you can use Object.assign()
.
let obj = {};
Object.assign(obj, {key1: 1});
Object.assign(obj, {key2: 'dog'});
What an exciting time to be alive.
Revise the code and make it more robust with proper test case and check an error there before implementing into a production environment.
Now you can solve your code error in less than a minute.
03.03.2020, 03:06 |
|||||||||||
|
|||||||||||
ошибка: Property does not exist on type сразу скажу я бэкэнд и мне просто нужно VIEW я просто повторяю один мануал из сети версии ангуляра видать разные и выходит шляпа:
сначала сделал как в мануале: import { Injectable } from '@angular/core'; import { Http, Response, Headers, RequestOptions } from '@angular/http'; import { Observable } from 'rxjs'; import { User } from './user'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; @Injectable() export class UserService{ constructor(private _httpService: Http){} getAllUsers(): Observable<User[]>{ return this._httpService.get("http://localhost:7777/webapp/user") .map((response: Response) => response.json()) .catch(this.handleError); } private handleError(error: Response){ return Observable.throw(error); } } но получаю ошибку:
долго и упорно гуглив понял что надо действовать иначе и переделал код: import { Injectable } from '@angular/core'; import { Http, Response, Headers, RequestOptions } from '@angular/http'; import { Observable } from 'rxjs'; import { User } from './user'; import { map } from 'rxjs/operators' @Injectable() export class UserService{ constructor(private _httpService: Http){} getUsers(){ return this._httpService.get("http://localhost:7777/webapp/user") .pipe(map((response: Response) => response.json()) .subscribe((response: Response) => { console.log(response) })); } private handleError(error: Response){ return Observable.throw(error); } } но теперь ошибка:
прошу поддержки что надо сделать чтобы заработало? |
03.03.2020, 03:27 |
||||
|
||||
Не выбирать angular если тебе просто нужен VIEW. __________________ 29375, 35 |
03.03.2020, 07:16 |
||||
|
||||
SadiQ228, getUsers(){ return this._httpService.get("http://localhost:7777/webapp/user") ну и в другом месте, где происходит вызов этого метода сервиса someFn() { this.userService.getUsers().subscribe(users => console.log(users), error => console.error(error)); } |
03.03.2020, 17:45 |
||||
|
||||
Сервис: import { Injectable } from '@angular/core'; import { Http, Response, Headers, RequestOptions } from '@angular/http'; import { Observable } from 'rxjs'; import { User } from './user'; @Injectable() export class UserService{ constructor(private _httpService: Http){} getAllUsers(){ return this._httpService.get("http://localhost:7777/webapp/user") } private handleError(error: Response){ return Observable.throw(error); } } компонент: import {Component, OnInit} from '@angular/core'; import {Router} from '@angular/router'; import {User} from './user'; import { UserService } from './user.service'; @Component({ selector: 'app-user', templateUrl: './user.component.html', styleUrls: ['./user.component.css'] }) export class UserComponent implements OnInit{ users: User[]; constructor(private _userService: UserService){} ngOnInit(): void { this.getUsers(); } getUsers(): void{ this._userService.getAllUsers().subscribe(users => console.log(users), error => console.error(error)); } } спасибо большое за подсказку, теперь проект компилируется!! однако после компиляции выдает ошибку:
|
04.03.2020, 00:01 |
|||
|
|||
мой package.json { "name": "webapp", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "~9.0.3", "@angular/common": "~9.0.3", "@angular/compiler": "~9.0.3", "@angular/core": "~9.0.3", "@angular/forms": "~9.0.3", "@angular/platform-browser": "~9.0.3", "@angular/platform-browser-dynamic": "~9.0.3", "@angular/router": "~9.0.3", "rxjs": "^6.5.4", "tslib": "^1.10.0", "zone.js": "~0.10.2" }, "devDependencies": { "@angular-devkit/build-angular": "~0.900.4", "@angular/cli": "^9.0.4", "@angular/compiler-cli": "~9.0.3", "@angular/language-service": "~9.0.3", "@types/jasmine": "~3.5.0", "@types/jasminewd2": "~2.0.3", "@types/node": "^12.11.1", "codelyzer": "^5.1.2", "jasmine-core": "~3.5.0", "jasmine-spec-reporter": "~4.2.1", "karma": "~4.3.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage-istanbul-reporter": "~2.1.0", "karma-jasmine": "~2.0.1", "karma-jasmine-html-reporter": "^1.4.2", "protractor": "~5.4.3", "rxjs-compat": "^6.5.4", "ts-node": "~8.3.0", "tslint": "~5.18.0", "typescript": "~3.7.5" } } |
04.03.2020, 06:18 |
||||
|
||||
SadiQ228, |
04.03.2020, 19:12 |
|||
|
|||
жалко в консоли не пишет номер строчки где менять надо меняю в сервисе и модуле и все равно ошибка блин может есть какие то методы диагностики я хз |