Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Compilation exception in mapped type #13044

Copy link
Copy link
@zamb3zi

Description

@zamb3zi
Issue body actions

TypeScript Version: nightly (2.2.0-dev.20161219)

Code

type Foo<T, F extends keyof T> = {
    pf: {[P in F]?: T[P]},
    pt: {[P in T]?: T[P]}, // note: should be in keyof T
};
type O = {x: number, y: boolean};
let o: O = {x: 5, y: false};
let f: Foo<O, 'x'> = {
    pf: {x: 7},
    pt: {x: 7, y: false},
};

Expected behavior:

Compiling only the first type declaration produces the following expected error:

$ node node_modules/typescript/bin/tsc test.ts
test.ts(4,16): error TS2322: Type '{}' is not assignable to type 'string'.
test.ts(4,21): error TS2536: Type 'P' cannot be used to index type 'T'.

Actual behavior:
Compiling the whole example with a clean nightly install without tsconfig produces:

$ node node_modules/typescript/bin/tsc test.ts
C:\Users\...\Documents\TCM\git\tmp\node_modules\typescript\lib\tsc.js:49834
                throw e;
                ^

TypeError: Cannot read property 'flags' of undefined
    at getModifiersTypeFromMappedType (C:\Users\...\Documents\TCM\git\tmp\node_modules\typescript\lib\tsc.js:23125:60)
    at resolveMappedTypeMembers (C:\Users\...\Documents\TCM\git\tmp\node_modules\typescript\lib\tsc.js:23068:49)
    at resolveStructuredTypeMembers (C:\Users\...\Documents\TCM\git\tmp\node_modules\typescript\lib\tsc.js:23153:25)
    at getPropertyOfType (C:\Users\...\Documents\TCM\git\tmp\node_modules\typescript\lib\tsc.js:23307:32)
    at C:\Users\...\Documents\TCM\git\tmp\node_modules\typescript\lib\tsc.js:28345:47
    at applyToContextualType (C:\Users\...\Documents\TCM\git\tmp\node_modules\typescript\lib\tsc.js:28321:24)
    at getTypeOfPropertyOfContextualType (C:\Users\...\Documents\TCM\git\tmp\node_modules\typescript\lib\tsc.js:28344:20)
    at getContextualTypeForObjectLiteralElement (C:\Users\...\Documents\TCM\git\tmp\node_modules\typescript\lib\tsc.js:28368:40)
    at getContextualType (C:\Users\...\Documents\TCM\git\tmp\node_modules\typescript\lib\tsc.js:28442:28)
    at checkExpressionForMutableLocation (C:\Users\...\Documents\TCM\git\tmp\node_modules\typescript\lib\tsc.js:31213:69)
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.