Closed
Description
Bug Report
π Search Terms
Signature Index with Utility Types
π Version & Regression Information
This happened with all versions I've tested including nightly
β― Playground Link
I don't have a playground link unfortunately, except my stackoverflow question:
https://stackoverflow.com/questions/67542115/typescript-compiler-failing-with-different-property-types-on-omit-and-index-sign/67542334
π» Code
interface Obj {
foo: number
bar: string
baz: number
}
type Sub = Omit<Obj, "baz">
const obj: Obj = {foo: 1, bar: "abc", baz: 1}
function fn (key: K, val: Sub[K]) {
obj[key] = val
}
π Actual behavior
Typescript should(?) have inferred the data type like it did without the utility type, but is requiring that data types be uniform on the utility type.
π Expected behavior
The compiler to still be able to compute the data type
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
whzx5byb commentedon May 15, 2021
See #31694 (comment)
MartinJohns commentedon May 15, 2021
stockson commentedon May 15, 2021
Just realized the angle brackets disappeared. Does that mean I can inject HTML? That's interesting.
Here's the playground link:
https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgPICMBWyDeBYAKGWRgHtSAuZEAVwFt1pDj04oqBnMKUAc2eSsAXlVoMmBAL6EwATwAOKAMo10yALxo6wMAB4MmADTIARMJMA+QoQA2EMMlJYqBjbjKVkARmOt2puHQEE184EW9pAkIYGhAEMGBSEBJk3QBpZAgAD0gQABMOZABrCFlSGGQVdAsAChLZKjTjADc4GyoqgG00gF0ASlwBJ0xO+p63VptCSSA
IllusionMH commentedon May 17, 2021
Looks like duplicate of #33014
RyanCavanaugh commentedon May 20, 2021
This is the intended behavior, because this is a legal call to your function: