Skip to content

Constraint failing for subtype (regression) #29464

Closed
@crystalin

Description

@crystalin

TypeScript Version:
Failing in 3.3.0-dev.20190117

Last version 3.1.6 passing the test

Search Terms:
satisfy constraint subtype FilterFlags

Code

function func1<Base extends { [key: string]: any }, Type extends Base[Key], Key extends keyof Base>(
  attrName: Key,
  attrType: Type
) {
  console.log("func1");
}

function func1String<Base extends { [key: string]: any }, Key extends keyof Base>(attrName: Key) {
  func1<Base, string, Key>(attrName, "string");
}

Expected behavior:
Compilation should pass (like it does on 3.1.6)

Actual behavior:
Compilation fails

test_ts.ts:18:15 - error TS2344: Type 'string' does not satisfy the constraint 'Base[Key]'.

18   func1<Base, string, Key>(attrName, "string");
                 ~~~~~~

Playground Link:
http://www.typescriptlang.org/play/#src=function%20func1%3CBase%20extends%20%7B%20%5Bkey%3A%20string%5D%3A%20any%20%7D%2C%20Type%20extends%20Base%5BKey%5D%2C%20Key%20extends%20keyof%20Base%3E(attrName%3A%20Key%2C%20attrType%3A%20Type)%20%7B%0D%0A%20%20%20%20console.log('func1')%0D%0A%7D%0D%0A%0D%0A%0D%0Afunction%20func1String%3CBase%20extends%20%7B%20%5Bkey%3A%20string%5D%3A%20any%20%7D%2C%20Key%20extends%20keyof%20Base%3E(attrName%3A%20Key)%20%7B%0D%0A%20%20%20%20func1%3CBase%2C%20string%2C%20Key%3E(attrName%2C%20%22string%22)%3B%0D%0A%7D

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions