Microsoft/TypeScript

Improve diagnostic when string from property is not assignable to string literal.

Open

#26.413 geöffnet am 13. Aug. 2018

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
Domain: Error MessagesEffort: ModerateHelp WantedSuggestion

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

TypeScript Version: 3.1.0-dev.20180810

Code

interface IceCreamOptions {
    readonly cherry: "yes" | "no"
}
declare function iceCream(options: IceCreamOptions): void;
const options = { cherry: "yes" };
iceCream(options);

Expected behavior:

Error message recommending to add a type annotation to options. This should be detectable because the source of the failing property is a PropertyAssignment in an object literal being assigned to a variable. (If there is no variable assignment, we could still recommend using ``"yes" as "yes"although that isn't as pretty.) Could also come with a codefix. Note that in JS the fix is slightly different: put/** @type {IceCreamOptions} /before theconstor use/* @type {"yes"} */ ("yes")`.

Actual behavior:

Error messages says Type 'string' is not assignable to type '"yes" | "no"'. with no information on how to fix it.

Contributor Guide