property does not exist on type object code example
Example 1: Property 'of' does not exist on type 'typeof Observable'.
import { of } from 'rxjs';
Example 2: Property 'on' does not exist on type 'HTMLElement'.
To prevent this error you can write:
var plotDiv: any = document.getElementById('myDiv');
plotDiv.on('plotly_relayout', ...
document.getElementById('myDiv') return HTMLElement. This type doesn't contain method
on because this method is added within plotly-latest.min.js. So in order to silence
the typescript warning you can explicity say compile not to check types for plotDiv
Another way is create type definition like:
interface PlotHTMLElement extends HTMLElement {
on(eventName: string, handler: Function): void;
}
var plotDiv = <PlotHTMLElement>document.getElementById('myDiv')
plotDiv.on('plotly_relayout', function() {
});
Example 3: Property 'find' does not exist on type NodeListOf
const elements = Array.from(document.querySelectorAll('.selector'));
elements.forEach((...) => {});
Example 4: property 'do' does not exist on type 'observable>'. angular 9
import { tap } from 'rxjs/operators';
const TOKEN_HEADER_KEY = 'Authorization';
@Injectable()
export class Interceptor implements HttpInterceptor {
constructor(private token: TokenStorage, private router: Router) { }
intercept(req: HttpRequest<any>, next: HttpHandler):
Observable<HttpSentEvent | HttpHeaderResponse | HttpProgressEvent | HttpResponse<any> | HttpUserEvent<any>> {
let authReq = req;
if (this.token.getToken() != null) {
authReq = req.clone({ headers: req.headers.set(TOKEN_HEADER_KEY, 'Bearer ' + this.token.getToken())});
}
return next.handle(authReq).pipe(tap(
(err: any) => {
if (err instanceof HttpErrorResponse) {
console.log(err);
console.log('req url :: ' + req.url);
if (err.status === 401) {
this.router.navigate(['user']);
}
}
}
));
}
}
Example 5: Property 'users' does not exist on type 'UsersDTO[]'. 29 if (saveUser.users.length < 1) {
// for JSON:
const { value } = ctx.request.body({ type: "json" });
const { text } = await value;
// for FormData:
const { value } = ctx.request.body({ type: "form-data" });
const formData = await value.read();
const { text } = formData.fields;