Ich habe gerade zwei wichtige Upgrades für unsere Angular 4-Anwendung und Build-Tools:Typ 'Headers' hat keine Eigenschaften gemeinsam mit dem Typ 'RequestOptionsArgs'?
- @ Winkel/Kern
^4.1.3
=>^4.2.4
(und/http,/Formulare, etc.) - tslint
^5.3.2
=>^5.4.3
ich habe einen Dienst, die Optionen wie erklärt so:
@Injectable()
export class WorkOrderService {
private headers: Headers = new Headers({ 'Content-Type': 'application/json' });
private options: RequestOptions = new RequestOptions(this.headers);
constructor(private http: Http) {}
/* Methods ... */
}
Die oben jetzt nicht mehr validiert tslint, wirft die folgenden Fehler:
error TS2559: Type 'Headers' has no properties in common with type 'RequestOptionsArgs'.
Die Quelle (@ Winkel/http interface.d.ts:43
) erlaubt deutlich für Headers
als RequestOptionsArgs
:
/**
* Interface for options to construct a RequestOptions, based on
* [RequestInit](https://fetch.spec.whatwg.org/#requestinit) from the Fetch spec.
*
* @experimental
*/
export interface RequestOptionsArgs {
url?: string | null;
method?: string | RequestMethod | null;
/** @deprecated from 4.0.0. Use params instead. */
search?: string | URLSearchParams | {
[key: string]: any | any[];
} | null;
params?: string | URLSearchParams | {
[key: string]: any | any[];
} | null;
headers?: Headers | null;
body?: any;
withCredentials?: boolean | null;
responseType?: ResponseContentType | null;
}
ich habe laufen in ähnlichen Problem zu sein, danken die für die Bereitstellung von eine Lösung –
Ich glaube, Sie brauchen nur Klammern um Ihre this.headers. neue RequestOptions ({this.headers}); – LLai
@LLai Die Destrukturierung von Objekten funktioniert in diesem Fall nicht, weil * this. *: 'Argument of type '{this: any; } 'kann nicht dem Parameter' RequestOptionsArgs 'zugewiesen werden. Das Objektliteral darf nur bekannte Eigenschaften angeben, und "das" existiert nicht im Typ "RequestOptionsArgs". Das hatte ich mir aber auch erhofft. – msanford