-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped typesHelp WantedYou can do thisYou can do this
Milestone
Description
Bug Report
🔎 Search Terms
mapped types, generic bound, nested objects
🕗 Version & Regression Information
We've detected this on 4.7.4. Checking previous versions on playgrounds, last one where it worked correctly is 3.5.1.
It is also reproducible on current nightly build.
- This changed between versions 3.5.1 and 3.6.3
⏯ Playground Link
Playground link with relevant code
💻 Code
type BaseType = {
select?: { id?: boolean} ,
where: {},
}
type FullType = BaseType & {
anything?: boolean
}
type MappedType<T> = {
[key in keyof T]: T[key]
}
declare function genericFunction<T extends FullType>(args: MappedType<T>): void
genericFunction({
where: {},
select: {
id: true,
// this should not pass
shouldErrorHere: 'lalalala'
}
})🙁 Actual behavior
The code passes typechecks
🙂 Expected behavior
shouldErrorHere property should not be allowed in that position, since it's not defined on typeof BaseType['select']. Doing any of the following causes expected error to appear:
- Removing intersection type and making
FullTypea plain alias forBaseType - Making
whereproperty optional inBaseTypedefinition - Removing
anythingproperty fromFullType - Adding any non-optional property to the intersection
- Omitting
whereproperty ingenericFunctioncall - Passing incorrect
anythingvalue during the call - Changing
FullTypetointerface FullType extends BaseType
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped typesHelp WantedYou can do thisYou can do this