microsoft / microsoft/TypeScript
strictNullCheck False Posivitve when access propery on created object.
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
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:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、TypeScript 3.5 時代の例とその tsconfig を使って診断を再現し、現在のコンパイラーと動作を比較します。object literals で初期化されたプロパティを type checker がどのように絞り込むかを調査し、動作が誤っていることが確認できた場合は regression test を追加します。strictNullChecks を弱めることなく、例で false-positive の診断が報告されなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100