microsoft / microsoft/TypeScript

strictNullCheck False Posivitve when access propery on created object.

Abierto
#31,202 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Domain: check: Control Flow Experience Enhancement Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

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:

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza reproduciendo el diagnóstico con el ejemplo de la era de TypeScript 3.5 y su tsconfig, y después compara el comportamiento con el compilador actual. Investiga cómo el type checker restringe las propiedades inicializadas en object literals y añade un regression test si se confirma que el comportamiento es incorrecto. Se considera terminado cuando el ejemplo ya no informa del diagnóstico false-positive sin debilitar strictNullChecks.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.