-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: 2.5.3 / nightly (2.5.0-dev.201xxxxx)
Code (gist)
type MyArgs = {
prop1:any;
prop2?:any;
}
interface IArgsHandler<TArgs extends MyArgs>
{
handle(args:TArgs):void;
}
function MyFunc<TMyArgs extends MyArgs>(args:TMyArgs, ...handlers:IArgsHandler<TMyArgs>[])
{
for(let handler of handlers||[])
{
handler.handle(args);
}
}
function exampleOfIssue()
{
MyFunc({prop1:123, newProp:"asdasd"},{
handle(a){
if(a.prop2) //Compilation error here: error TS2551: Property 'prop2' does not exist on type '{ prop1: number; newProp: string; }'. Did you mean 'prop1'?
{
console.log("There is prop2");
}
}
})
}
Expected behavior:
Compilation successfull, because TMyArgs extends MyArgs, which has prop2.
Actual behavior:
Compilation error here: error TS2551: Property 'prop2' does not exist on type '{ prop1: number; newProp: string; }'. Did you mean 'prop1'?
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug