-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(43030): fix instantiated null/undefined type from JS initializer (#…
- Loading branch information
1 parent
bb6d8a7
commit 463c794
Showing
15 changed files
with
366 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
=== tests/cases/conformance/salsa/a.js === | ||
/** @type {() => undefined} */ | ||
function f1() { | ||
>f1 : Symbol(f1, Decl(a.js, 0, 0)) | ||
|
||
return undefined; | ||
>undefined : Symbol(undefined) | ||
} | ||
const a = f1() | ||
>a : Symbol(a, Decl(a.js, 4, 5)) | ||
>f1 : Symbol(f1, Decl(a.js, 0, 0)) | ||
|
||
/** @type {() => null} */ | ||
function f2() { | ||
>f2 : Symbol(f2, Decl(a.js, 4, 14)) | ||
|
||
return null; | ||
} | ||
const b = f2() | ||
>b : Symbol(b, Decl(a.js, 10, 5)) | ||
>f2 : Symbol(f2, Decl(a.js, 4, 14)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
=== tests/cases/conformance/salsa/a.js === | ||
/** @type {() => undefined} */ | ||
function f1() { | ||
>f1 : () => undefined | ||
|
||
return undefined; | ||
>undefined : undefined | ||
} | ||
const a = f1() | ||
>a : undefined | ||
>f1() : undefined | ||
>f1 : () => undefined | ||
|
||
/** @type {() => null} */ | ||
function f2() { | ||
>f2 : () => null | ||
|
||
return null; | ||
>null : null | ||
} | ||
const b = f2() | ||
>b : null | ||
>f2() : null | ||
>f2 : () => null | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
=== tests/cases/conformance/salsa/a.js === | ||
/** @type {() => undefined} */ | ||
function f1() { | ||
>f1 : Symbol(f1, Decl(a.js, 0, 0)) | ||
|
||
return undefined; | ||
>undefined : Symbol(undefined) | ||
} | ||
const a = f1() | ||
>a : Symbol(a, Decl(a.js, 4, 5)) | ||
>f1 : Symbol(f1, Decl(a.js, 0, 0)) | ||
|
||
/** @type {() => null} */ | ||
function f2() { | ||
>f2 : Symbol(f2, Decl(a.js, 4, 14)) | ||
|
||
return null; | ||
} | ||
const b = f2() | ||
>b : Symbol(b, Decl(a.js, 10, 5)) | ||
>f2 : Symbol(f2, Decl(a.js, 4, 14)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
=== tests/cases/conformance/salsa/a.js === | ||
/** @type {() => undefined} */ | ||
function f1() { | ||
>f1 : () => undefined | ||
|
||
return undefined; | ||
>undefined : undefined | ||
} | ||
const a = f1() | ||
>a : undefined | ||
>f1() : undefined | ||
>f1 : () => undefined | ||
|
||
/** @type {() => null} */ | ||
function f2() { | ||
>f2 : () => null | ||
|
||
return null; | ||
>null : null | ||
} | ||
const b = f2() | ||
>b : null | ||
>f2() : null | ||
>f2 : () => null | ||
|
35 changes: 35 additions & 0 deletions
35
tests/baselines/reference/typeFromJSInitializer4.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
tests/cases/conformance/salsa/a.js(5,12): error TS7006: Parameter 'a' implicitly has an 'any' type. | ||
tests/cases/conformance/salsa/a.js(5,29): error TS7006: Parameter 'l' implicitly has an 'any[]' type. | ||
tests/cases/conformance/salsa/a.js(17,5): error TS2322: Type 'string' is not assignable to type 'number'. | ||
|
||
|
||
==== tests/cases/conformance/salsa/a.js (3 errors) ==== | ||
/** @type {number | undefined} */ | ||
var n; | ||
|
||
// should get any on parameter initialisers | ||
function f(a = null, b = n, l = []) { | ||
~~~~~~~~ | ||
!!! error TS7006: Parameter 'a' implicitly has an 'any' type. | ||
~~~~~~ | ||
!!! error TS7006: Parameter 'l' implicitly has an 'any[]' type. | ||
// a should be any | ||
a = undefined | ||
a = null | ||
a = 1 | ||
a = true | ||
a = {} | ||
a = 'ok' | ||
|
||
// b should be number | undefined, not any | ||
b = 1 | ||
b = undefined | ||
b = 'error' | ||
~ | ||
!!! error TS2322: Type 'string' is not assignable to type 'number'. | ||
|
||
// l should be any[] | ||
l.push(1) | ||
l.push('ok') | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
=== tests/cases/conformance/salsa/a.js === | ||
/** @type {number | undefined} */ | ||
var n; | ||
>n : Symbol(n, Decl(a.js, 1, 3)) | ||
|
||
// should get any on parameter initialisers | ||
function f(a = null, b = n, l = []) { | ||
>f : Symbol(f, Decl(a.js, 1, 6)) | ||
>a : Symbol(a, Decl(a.js, 4, 11)) | ||
>b : Symbol(b, Decl(a.js, 4, 20)) | ||
>n : Symbol(n, Decl(a.js, 1, 3)) | ||
>l : Symbol(l, Decl(a.js, 4, 27)) | ||
|
||
// a should be any | ||
a = undefined | ||
>a : Symbol(a, Decl(a.js, 4, 11)) | ||
>undefined : Symbol(undefined) | ||
|
||
a = null | ||
>a : Symbol(a, Decl(a.js, 4, 11)) | ||
|
||
a = 1 | ||
>a : Symbol(a, Decl(a.js, 4, 11)) | ||
|
||
a = true | ||
>a : Symbol(a, Decl(a.js, 4, 11)) | ||
|
||
a = {} | ||
>a : Symbol(a, Decl(a.js, 4, 11)) | ||
|
||
a = 'ok' | ||
>a : Symbol(a, Decl(a.js, 4, 11)) | ||
|
||
// b should be number | undefined, not any | ||
b = 1 | ||
>b : Symbol(b, Decl(a.js, 4, 20)) | ||
|
||
b = undefined | ||
>b : Symbol(b, Decl(a.js, 4, 20)) | ||
>undefined : Symbol(undefined) | ||
|
||
b = 'error' | ||
>b : Symbol(b, Decl(a.js, 4, 20)) | ||
|
||
// l should be any[] | ||
l.push(1) | ||
>l.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) | ||
>l : Symbol(l, Decl(a.js, 4, 27)) | ||
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) | ||
|
||
l.push('ok') | ||
>l.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) | ||
>l : Symbol(l, Decl(a.js, 4, 27)) | ||
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) | ||
} | ||
|
Oops, something went wrong.