-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Description
Bug Report
function inferType(value: string) {
const asBoolean: boolean | null = null;
const asDate: Date | null = null;
const asDouble: number | null = null;
const asLong: number | null = null;
const asURL: URL | null = null;
return {
value_as_string: value,
value_as_boolean: asBoolean,
value_as_date: asDate,
value_as_double: asDouble,
value_as_long: asLong,
value_as_url: asURL,
};
}
type EventMetaData = {
key: string;
value_as_string: string;
value_as_boolean: boolean | null;
value_as_date: string | null;
value_as_long: number | null;
value_as_double: number | null;
};
function convert(key: string, value: string): EventMetaData {
const types = inferType(value);
return {
key: key,
...types // Expect error here because `value_as_url` is not allowed
};
}Would expect the following error (or something like that):
Type '{ value_as_url: URL; value_as_string: string; value_as_boolean: null; value_as_date: null; value_as_double: null; value_as_long: null; key: string; }' is not assignable to type 'EventMetaData'.
Object literal may only specify known properties, and 'value_as_url' does not exist in type 'EventMetaData'.(2322)
🔎 Search Terms
object spread extra properties expected error
🕗 Version & Regression Information
Using TypeScript 4.1.5
⏯ Playground Link
Metadata
Metadata
Assignees
Labels
No labels