normally generic types can be inferred by their related args,
thing1, inferred correctly;
while in thing2, i explicitly set the first type parameter, and its key is inferred as "any", which is the default type of the second type parameter;
why? is this a fact?
i don't recall this being mentioned in typescriptlang.org.
type CreateThingOption<
Value = any,
Key extends string = any,
> = {
key: Key;
serialize?: () => Value;
}
function createThing<
Value = any,
Key extends string = any,
>
(option: CreateThingOption<Value, Key>) {
return option
}
let thing1 = createThing({
key: '1',
})
type Key1Type = typeof thing1['key'] // "1"
let thing2 = createThing<string>({
key: '2',
})
type Key2Type = typeof thing2['key'] // any. WHY???