I am trying to write a typescript class with private properties, but these properties are set in constructor, the constructor needs only an object, but I always get an error, that "error TS2345: Argument of type 'TranslateResponse' is not assignable to parameter of type '{ status: "success" | "failed"; errorCode?: number | undefined; message?: string | undefined; data?: any; }'. 2023-05-30 13:45:24 translator-angular | Property 'status' is private in type 'TranslateResponse' but not in type '{ status: "success" | "failed"; errorCode?: number | undefined; message?: string | undefined; data?: any; }'. I don't understand, what meaning does it have, if an object's property is private, or public? I read some stories about that, but they all were issues with interfaces, but I don't have any interface.
export class FileTranslatedSuccess {
private newFilePath!: string;
private newFileName!: string;
private targetLanguage!: LanguageCode;
constructor(object: {newFilePath: string, newFileName: string, targetLanguage: LanguageCode}) {
this.newFilePath = object.newFilePath;
this.newFileName = object.newFileName;
this.targetLanguage = object.targetLanguage;
}
And that constructor gets an object here:
constructor(object: {
fileTranslatedSuccess: {[key: string]: FileTranslatedSuccess[]},
fileTranslatedFailed: {originalFile: string, targetLanguage: LanguageCode, message: string}[] | ""
}) {
let keys = Object.keys(object.fileTranslatedSuccess);
this.fileTranslatedSuccess = {};
keys.forEach(key => {
this.fileTranslatedSuccess[key] = [];
object.fileTranslatedSuccess[key].forEach(fileTranslatedSuccess => {
this.fileTranslatedSuccess[key].push(new FileTranslatedSuccess(fileTranslatedSuccess));
});
});
if (object.fileTranslatedFailed === "") {
this.fileTranslatedFailed = "";
} else {
this.fileTranslatedFailed = [];
object.fileTranslatedFailed.forEach(fileTranslatedFailed => {
if (Array.isArray(this.fileTranslatedFailed)) {
this.fileTranslatedFailed.push(new FileTranslatedFailed(fileTranslatedFailed));
}
});
}
}
That is the constructor of an other object. The error is pointing on the instantiating of FileTranslatedSuccess class. ( this.fileTranslatedSuccess[key].push(new FileTranslatedSuccess(fileTranslatedSuccess)); ). Could someone explain to me, why is it an error, if I set private properties in constructor from an object with public properties?