Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infer recursive type (Typescript) #47984

Closed
MikkelSnitker opened this issue Apr 16, 2018 · 1 comment
Closed

infer recursive type (Typescript) #47984

MikkelSnitker opened this issue Apr 16, 2018 · 1 comment
Assignees
Labels
typescript Typescript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)

Comments

@MikkelSnitker
Copy link

MikkelSnitker commented Apr 16, 2018

Hi.
I'm not sure if this is a bug/feature in vscode or in typescript, but recursive types resolves to any?
Giving the code below TestType3 resolves to:

TypeScript Type<{prop1: Type<String>,prop2: Type<any>}>
and not as i expected
TypeScript Type<{prop1: Type<String>,prop2: Type<{subprop: Type<String>}>

I'm not sure if this is a typescript issue, but the compiler catches the error if prop2 does not contain a string property with the name subprop.

type Constructor<T> = { new(...args: any[]): T }
type Type<T> = T & { validate?: (value:any)=>boolean};
type InferTest<T> = T extends Constructor<infer T1> ? Type<T1>: 
T extends Array<Constructor<infer T1>> ? Array<Type<T1>>:
Type<{[K in keyof T]: InferTest<T[K]> }> 

declare function Test1<T>(o: T): InferTest<T>;

const TestType1 = Test1(Number) // Type<Number>;
const TestType2 = Test1([Number]) // Type<Number>[];
const TestType3 = Test1({
    prop1: String,
    prop2: {
        subprop: String
    }
}) // Type<{prop1: Type<String>,prop2: Type<any>}> 

var test4: typeof TestType3 = {
    prop1: "Hello World!",
    prop2: { 
        subprop: 4 
    }
}
  • VSCode Version: 1.22.1
  • OS Version: 10.13.3

Does this issue occur when all extensions are disabled?: Yes

Regards Mikkel

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 16, 2018

This issue was moved to microsoft/TypeScript#23433

@mjbvz mjbvz closed this as completed Apr 16, 2018
@mjbvz mjbvz added the upstream Issue identified as 'upstream' component related (exists outside of VS Code) label Apr 16, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
typescript Typescript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Projects
None yet
Development

No branches or pull requests

2 participants