Add assignability tests for initialised parameters
This commit is contained in:
parent
eaca169b11
commit
533ce824e8
|
@ -18,10 +18,12 @@ function foo2(x = "string", b: number) {
|
|||
|
||||
function foo3(x: string | undefined = "string", b: number) {
|
||||
x.length; // ok, should be string
|
||||
x = undefined;
|
||||
}
|
||||
|
||||
function foo4(x: string | undefined = undefined, b: number) {
|
||||
x; // should be string | undefined
|
||||
x = undefined;
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,10 +74,12 @@ function foo2(x, b) {
|
|||
function foo3(x, b) {
|
||||
if (x === void 0) { x = "string"; }
|
||||
x.length; // ok, should be string
|
||||
x = undefined;
|
||||
}
|
||||
function foo4(x, b) {
|
||||
if (x === void 0) { x = undefined; }
|
||||
x; // should be string | undefined
|
||||
x = undefined;
|
||||
}
|
||||
// .d.ts should have `string | undefined` for foo1, foo2, foo3 and foo4
|
||||
foo1(undefined, 1);
|
||||
|
|
|
@ -66,16 +66,24 @@ function foo3(x: string | undefined = "string", b: number) {
|
|||
>x.length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 17, 14))
|
||||
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
|
||||
|
||||
x = undefined;
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 17, 14))
|
||||
>undefined : Symbol(undefined)
|
||||
}
|
||||
|
||||
function foo4(x: string | undefined = undefined, b: number) {
|
||||
>foo4 : Symbol(foo4, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 19, 1))
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 21, 14))
|
||||
>foo4 : Symbol(foo4, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 20, 1))
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 22, 14))
|
||||
>undefined : Symbol(undefined)
|
||||
>b : Symbol(b, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 21, 48))
|
||||
>b : Symbol(b, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 22, 48))
|
||||
|
||||
x; // should be string | undefined
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 21, 14))
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 22, 14))
|
||||
|
||||
x = undefined;
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 22, 14))
|
||||
>undefined : Symbol(undefined)
|
||||
}
|
||||
|
||||
|
||||
|
@ -94,40 +102,40 @@ foo3(undefined, 1);
|
|||
>undefined : Symbol(undefined)
|
||||
|
||||
foo4(undefined, 1);
|
||||
>foo4 : Symbol(foo4, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 19, 1))
|
||||
>foo4 : Symbol(foo4, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 20, 1))
|
||||
>undefined : Symbol(undefined)
|
||||
|
||||
|
||||
function removeUndefinedButNotFalse(x = true) {
|
||||
>removeUndefinedButNotFalse : Symbol(removeUndefinedButNotFalse, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 31, 19))
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 34, 36))
|
||||
>removeUndefinedButNotFalse : Symbol(removeUndefinedButNotFalse, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 33, 19))
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 36, 36))
|
||||
|
||||
if (x === false) {
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 34, 36))
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 36, 36))
|
||||
|
||||
return x;
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 34, 36))
|
||||
>x : Symbol(x, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 36, 36))
|
||||
}
|
||||
}
|
||||
|
||||
declare const cond: boolean;
|
||||
>cond : Symbol(cond, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 40, 13))
|
||||
>cond : Symbol(cond, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 42, 13))
|
||||
|
||||
function removeNothing(y = cond ? true : undefined) {
|
||||
>removeNothing : Symbol(removeNothing, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 40, 28))
|
||||
>y : Symbol(y, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 41, 23))
|
||||
>cond : Symbol(cond, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 40, 13))
|
||||
>removeNothing : Symbol(removeNothing, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 42, 28))
|
||||
>y : Symbol(y, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 43, 23))
|
||||
>cond : Symbol(cond, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 42, 13))
|
||||
>undefined : Symbol(undefined)
|
||||
|
||||
if (y !== undefined) {
|
||||
>y : Symbol(y, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 41, 23))
|
||||
>y : Symbol(y, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 43, 23))
|
||||
>undefined : Symbol(undefined)
|
||||
|
||||
if (y === false) {
|
||||
>y : Symbol(y, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 41, 23))
|
||||
>y : Symbol(y, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 43, 23))
|
||||
|
||||
return y;
|
||||
>y : Symbol(y, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 41, 23))
|
||||
>y : Symbol(y, Decl(defaultParameterAddsUndefinedWithStrictNullChecks.ts, 43, 23))
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -86,7 +86,7 @@ function foo2(x = "string", b: number) {
|
|||
|
||||
function foo3(x: string | undefined = "string", b: number) {
|
||||
>foo3 : (x: string | undefined, b: number) => void
|
||||
>x : string
|
||||
>x : string | undefined
|
||||
>"string" : "string"
|
||||
>b : number
|
||||
|
||||
|
@ -94,6 +94,11 @@ function foo3(x: string | undefined = "string", b: number) {
|
|||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
|
||||
x = undefined;
|
||||
>x = undefined : undefined
|
||||
>x : string | undefined
|
||||
>undefined : undefined
|
||||
}
|
||||
|
||||
function foo4(x: string | undefined = undefined, b: number) {
|
||||
|
@ -104,6 +109,11 @@ function foo4(x: string | undefined = undefined, b: number) {
|
|||
|
||||
x; // should be string | undefined
|
||||
>x : string | undefined
|
||||
|
||||
x = undefined;
|
||||
>x = undefined : undefined
|
||||
>x : string | undefined
|
||||
>undefined : undefined
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,10 +19,12 @@ function foo2(x = "string", b: number) {
|
|||
|
||||
function foo3(x: string | undefined = "string", b: number) {
|
||||
x.length; // ok, should be string
|
||||
x = undefined;
|
||||
}
|
||||
|
||||
function foo4(x: string | undefined = undefined, b: number) {
|
||||
x; // should be string | undefined
|
||||
x = undefined;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue