diff --git a/tests/cases/conformance/jsdoc/checkJsdocTypeTag1.ts b/tests/cases/conformance/jsdoc/checkJsdocTypeTag1.ts index 4dc7b934571..87e799e793c 100644 --- a/tests/cases/conformance/jsdoc/checkJsdocTypeTag1.ts +++ b/tests/cases/conformance/jsdoc/checkJsdocTypeTag1.ts @@ -23,7 +23,7 @@ x(1); /** @type {function} */ const y = (a) => a + 1; -x(1); +y(1); /** @type {function (number)} */ const x1 = (a) => a + 1; @@ -41,4 +41,4 @@ var props = {}; /** * @type {Object} */ -var props = {}; \ No newline at end of file +var props = {}; diff --git a/tests/cases/conformance/jsdoc/jsdocFunctionType.ts b/tests/cases/conformance/jsdoc/jsdocFunctionType.ts new file mode 100644 index 00000000000..0be247a9494 --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocFunctionType.ts @@ -0,0 +1,35 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @noImplicitAny: true + +// @Filename: functions.js + +/** + * @param {function(this: string, number): number} c is just passing on through + * @return {function(this: string, number): number} + */ +function id1(c) { + return c +} + +var x = id1(function (n) { return this.length + n }); + +/** + * @param {function(new: { length: number }, number): number} c is just passing on through + * @return {function(new: { length: number }, number): number} + */ +function id2(c) { + return c +} + +class C { + /** @param {number} n */ + constructor(n) { + this.length = n; + } +} + +var y = id2(C); +var z = new y(12); +z.length; diff --git a/tests/cases/conformance/jsdoc/jsdocInTypescript.ts b/tests/cases/conformance/jsdoc/jsdocInTypescript.ts new file mode 100644 index 00000000000..fbe8982f891 --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocInTypescript.ts @@ -0,0 +1,23 @@ +// @strict: true + +// grammar error from checker +var ara: Array. = [1,2,3]; + +function f(x: ?number, y: Array.) { + return x ? x + y[1] : y[0]; +} +function hof(ctor: function(new: number, string)) { + return new ctor('hi'); +} +function hof2(f: function(this: number, string): string) { + return f(12, 'hullo'); +} +var whatevs: * = 1001; +var ques: ? = 'what'; +var g: function(number, number): number = (n,m) => n + m; +var variadic: ...boolean = [true, false, true]; +var most: !string = 'definite'; +var weird1: new:string = {}; +var weird2: this:string = {}; +var postfixdef: number! = 101; +var postfixopt: number? = undefined; diff --git a/tests/cases/conformance/jsdoc/jsdocInTypescript2.ts b/tests/cases/conformance/jsdoc/jsdocInTypescript2.ts new file mode 100644 index 00000000000..2df22f3e4ab --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocInTypescript2.ts @@ -0,0 +1,2 @@ +// parse error (blocks grammar errors from checker) +function parse1(n: number=) { } diff --git a/tests/cases/conformance/jsdoc/jsdocTemplateTag.ts b/tests/cases/conformance/jsdoc/jsdocTemplateTag.ts index 42b21cf935b..79dc083a952 100644 --- a/tests/cases/conformance/jsdoc/jsdocTemplateTag.ts +++ b/tests/cases/conformance/jsdoc/jsdocTemplateTag.ts @@ -1,11 +1,12 @@ // @allowJs: true // @checkJs: true // @noEmit: true +// @Filename: forgot.js /** * @param {T} a * @template T */ -function f(a: T) { +function f(a) { return () => a } let n = f(1)() @@ -15,7 +16,7 @@ let n = f(1)() * @template T * @returns {function(): T} */ -function g(a: T) { +function g(a) { return () => a } let s = g('hi')() diff --git a/tests/cases/conformance/jsdoc/jsdocTypesInTypeAnnotations.ts b/tests/cases/conformance/jsdoc/jsdocTypesInTypeAnnotations.ts new file mode 100644 index 00000000000..b2e7d122199 --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocTypesInTypeAnnotations.ts @@ -0,0 +1,22 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @module: commonjs +// @filename: node.d.ts +// @noImplicitAny: true +declare function require(id: string): any; +declare var module: any, exports: any; + +// @filename: f.js +var F = function () { + this.x = 1; +}; + +function f(p: F) { p.x; } + +// @filename: normal.ts +class C { p: number } + +/** @param {C} p */ +function g(c) { return c.p } + diff --git a/tests/cases/conformance/jsdoc/syntaxErrors.ts b/tests/cases/conformance/jsdoc/syntaxErrors.ts index 4f9024810dd..847a99a5a12 100644 --- a/tests/cases/conformance/jsdoc/syntaxErrors.ts +++ b/tests/cases/conformance/jsdoc/syntaxErrors.ts @@ -2,19 +2,13 @@ // @allowJs: true // @noEmit: true -// @Filename: foo.js -/** - * @param {(x)=>void} x - * @param {typeof String} y - * @param {string & number} z - **/ -function foo(x, y, z) { } +// @Filename: dummyType.d.ts +declare class C { t: T } -// @Filename: skipped.js -// @ts-nocheck -/** - * @param {(x)=>void} x - * @param {typeof String} y - * @param {string & number} z - **/ -function bar(x, y, z) { } +// @Filename: badTypeArguments.js +/** @param {C.<>} x */ +/** @param {C.} y */ +function f(x, y) { + return x.t + y.t; +} +var x = f({ t: 1000 }, { t: 3000 }); diff --git a/tests/cases/fourslash/formatEmptyParamList.ts b/tests/cases/fourslash/formatEmptyParamList.ts index a5372010baa..1822506d486 100644 --- a/tests/cases/fourslash/formatEmptyParamList.ts +++ b/tests/cases/fourslash/formatEmptyParamList.ts @@ -2,4 +2,4 @@ ////function f( f: function){/*1*/ goTo.marker("1"); edit.insert("}"); -verify.currentLineContentIs("function f(f: function){ }") \ No newline at end of file +verify.currentLineContentIs("function f(f: function) { }")