-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
TypeScript Version: 3.6.0-dev.20190719
Search Terms:
Mapped types extends Index types
Code
type constr<Source, Tgt> = {[K in keyof Source]: string } &Pick<Tgt, Exclude<keyof Tgt, keyof Source>>
type s = constr<{}, {
[key: string]: {
a: string;
};
}>
declare const q: s
q["asd"].a.substr(1) //see: a is a string
q["asd"].b //and of course b does not exist (this line will have an error)
//but I expect the following line to error as well
const d: {[key: string]: {a: string, b: string}} = q
//and verify to be "no" (instead it is "yes")
type verify = s extends {[key: string]: {a: string, b: string}} ? "yes" : "no"
// the error _is_ shown if you construct a (seemingly identical) type by hand
type sManual = {} & Pick<{
[key: string]: {
a: string;
};
}, string | number>
declare const qManual: sManual
// see: error here
const dManual: {[key: string]: {a: string, b: string}} = qManual
//the error is also shown if I replace the indexed type with an actual property
type s2 = constr<{}, {
asd: {
a: string;
};
}>
declare const q2: s2
q2.asd.a.substr(1) //this is the same
q2.asd.b //this also
//But this is now an error (as it should be)
const d2: {asd: {a: string, b: string}} = q2
//and this is "no" (as it should be)
type verify2 = s2 extends {asd: {a: string, b: string}} ? "yes" : "no"Expected behavior:
As described inline. I do not think q should be assignable to d
Actual behavior:
q is assignable to d
Related Issues: Sorry, no. But as evidenced by my search terms I have some trouble finding the right words to describe the bug
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue