microsoft / microsoft/TypeScript
strictNullCheck False Posivitve when access propery on created object.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
TypeScript Version: 3.5.0-dev.20190501
Search Terms:
strict false positive object
Code
import * as azure from "@azure/storage-blob";
interface ISaveBlobOptions {
blobName: string;
contentDisposition?: {
fileName: string;
type: "inline" | "attachment";
};
contentType: string;
fileData: Buffer;
}
const saveBlobBase = async (input: ISaveBlobOptions): Promise<void> => {
this.validateSaveBlobBase(input);
await this.createStorage();
const options: azure.IBlockBlobUploadOptions = {
blobHTTPHeaders: {
blobContentType: input.contentType
}
};
if(input.contentDisposition) {
// Getting Object is possibly 'undefined'.
options.blobHTTPHeaders.blobContentDisposition = `${input.contentDisposition.type}; filename="${input.contentDisposition.fileName}"`;
}
if (input.fileData instanceof Buffer) {
await this.saveBlobBuffer(input.blobName, input.fileData, options);
} else if(this.isMulterFile(input.fileData)) {
await this.saveBlobMulterFile(input.blobName, input.fileData, options);
} else {
throw new Error("Unknown type for param file");
}
}
saveBlobBase({
blobName: "myBlobName",
contentDisposition: {
fileName: "foo.bar",
type: "inline"
},
contentType: "text/plain",
fileData: Buffer.from("SOME TEXT")
});
tsconfig
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"sourceMap": true,
"strictPropertyInitialization": true,
"strictNullChecks": true
}
}
Expected behavior:
since when the creating the options variable the property blobHTTPHeaders is also defined. I would expect that accessing properties off of blobHTTPHeaders should not throw a "Object is possibly 'undefined'."
Actual behavior:
Getting Object is possibly 'undefined'.
Playground Link:
Related Issues:
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Diagnose mit dem Beispiel aus der TypeScript-3.5-Ära und seiner tsconfig zu reproduzieren, und vergleiche dann das Verhalten mit dem aktuellen Compiler. Untersuche, wie der type checker Eigenschaften eingrenzt, die in object literals initialisiert werden, und füge einen regression test hinzu, wenn sich bestätigt, dass das Verhalten inkorrekt ist. Als erledigt gilt die Aufgabe, wenn das Beispiel die false-positive-Diagnose nicht mehr meldet, ohne strictNullChecks abzuschwächen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100