小编eco*_*747的帖子

错误的功能分配

我在非严格模式下遇到问题,这是我的代码,我可以将类型错误的函数分配给类型化变量。

我做错了吗?

谢谢。

interface A {
    f1( ) : void;
}

interface B extends A {
    f2( ) : void;
}

interface C {
    f3( ) : void;
}

type expectA = ( a: A ) => void;
type expectB = ( b: B ) => void;


function testA( a: A ) {
    console.log( "a" );
}

function testB( b: B ) {
    console.log( "b" );
}

function testC( c: C ) {
    console.log( "c" );
}


let v1: expectA …
Run Code Online (Sandbox Code Playgroud)

typechecking typescript

5
推荐指数
1
解决办法
59
查看次数

标签 统计

typechecking ×1

typescript ×1