You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Code
This is from code using the https://github.com/pelotom/runtypes package, I've tried to make it as self-contained as possible, but it's still quite long, sorry.
exportinterfaceRuntype<A>{_falseWitness: A;}exportinterfaceRecord<Oextends{[_: string]: Runtype<{}>;}>extendsRuntype<{[KinkeyofO]: O[K]['_falseWitness'];}>{tag: 'record';fields: O;}constRecord=<Oextends{[_: string]: Runtype<{}>;}>(fields: O): Record<O>=>({tag: 'record',
fields,_falseWitness: undefinedasany,});constCompanyData=Record({});constCompany=Record({companyData: CompanyData,});exportconstCompanyWrapper=Record({company: Company,});CompanyWrapper;// correctly inferred to be Record<{ company: Record<{ companyData: Record<{}>; }>; }>;CompanyWrapper._falseWitness;// incorrectly inferred to be { company: any; }CompanyWrapper._falseWitness.company.companyData;// CompanyWrapper._falseWitness.company.x; // this would correctly error even given the incorrect inferred type aboveexportinterfaceAPICall<Response>{readonlyResponseType: Runtype<Response>;}exportconstcompanyCall: APICall<typeofCompanyWrapper['_falseWitness']>={ResponseType: CompanyWrapper};exportconstcompanyAPI={getCompany: companyCall,};
Expected behavior:
getCompany is emitted with the correct type (APICall<Record<{ company: Record<{ companyData: Record<{}>; }>; }>>) in the output declaration
_falseWitness member is inferred to be the correct type in IntelliSense (see comments inline in code above)
Actual behavior:
The following declaration is emitted - company member in getCompany is inferred to be any.
This happens even with noImplicitAny where no any types should be introduced.
Workaround:
There is a workaround (although very annoying to remember to do as this introduction of any is often not easy to detect and bugs can be introduced) - wrap the CompanyWrapper type in an interface:
TypeScript Version: 2.7.0-dev.20171029
Code
This is from code using the https://github.com/pelotom/runtypes package, I've tried to make it as self-contained as possible, but it's still quite long, sorry.
Expected behavior:
getCompany
is emitted with the correct type (APICall<Record<{ company: Record<{ companyData: Record<{}>; }>; }>>
) in the output declaration_falseWitness
member is inferred to be the correct type in IntelliSense (see comments inline in code above)Actual behavior:
The following declaration is emitted -
company
member ingetCompany
is inferred to beany
.This happens even with
noImplicitAny
where noany
types should be introduced.Workaround:
There is a workaround (although very annoying to remember to do as this introduction of any is often not easy to detect and bugs can be introduced) - wrap the CompanyWrapper type in an interface:
The text was updated successfully, but these errors were encountered: