-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
444 additions
and
130 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
tests/cases/compiler/APISample_jsdoc.ts(79,32): error TS2495: Type '{ [x: number]: readonly JSDocParameterTag[]; hasTrailingComma?: readonly JSDocParameterTag[] | undefined; length: readonly JSDocParameterTag[]; toString: readonly JSDocParameterTag[]; toLocaleString: readonly JSDocParameterTag[]; concat: readonly JSDocParameterTag[]; join: readonly JSDocParameterTag[]; slice: readonly JSDocParameterTag[]; indexOf: readonly JSDocParameterTag[]; lastIndexOf: readonly JSDocParameterTag[]; every: readonly JSDocParameterTag[]; some: readonly JSDocParameterTag[]; forEach: readonly JSDocParameterTag[]; map: readonly JSDocParameterTag[]; filter: readonly JSDocParameterTag[]; reduce: readonly JSDocParameterTag[]; reduceRight: readonly JSDocParameterTag[]; pos: readonly JSDocParameterTag[]; end: readonly JSDocParameterTag[]; }' is not an array type or a string type. | ||
|
||
|
||
==== tests/cases/compiler/node_modules/typescript/index.d.ts (0 errors) ==== | ||
declare module "typescript" { | ||
export = ts; | ||
} | ||
|
||
==== tests/cases/compiler/APISample_jsdoc.ts (1 errors) ==== | ||
/* | ||
* Note: This test is a public API sample. The original sources can be found | ||
* at: https://github.com/YousefED/typescript-json-schema | ||
* https://github.com/vega/ts-json-schema-generator | ||
* Please log a "breaking change" issue for any API breaking change affecting this issue | ||
*/ | ||
|
||
declare var console: any; | ||
|
||
import * as ts from "typescript"; | ||
|
||
// excerpted from https://github.com/YousefED/typescript-json-schema | ||
// (converted from a method and modified; for example, `this: any` to compensate, among other changes) | ||
function parseCommentsIntoDefinition(this: any, | ||
symbol: ts.Symbol, | ||
definition: {description?: string, [s: string]: string | undefined}, | ||
otherAnnotations: { [s: string]: true}): void { | ||
if (!symbol) { | ||
return; | ||
} | ||
|
||
// the comments for a symbol | ||
let comments = symbol.getDocumentationComment(undefined); | ||
|
||
if (comments.length) { | ||
definition.description = comments.map(comment => comment.kind === "lineBreak" ? comment.text : comment.text.trim().replace(/\r\n/g, "\n")).join(""); | ||
} | ||
|
||
// jsdocs are separate from comments | ||
const jsdocs = symbol.getJsDocTags(); | ||
jsdocs.forEach(doc => { | ||
// if we have @TJS-... annotations, we have to parse them | ||
const { name, text } = doc; | ||
if (this.userValidationKeywords[name]) { | ||
definition[name] = this.parseValue(text); | ||
} else { | ||
// special annotations | ||
otherAnnotations[doc.name] = true; | ||
} | ||
}); | ||
} | ||
|
||
|
||
// excerpted from https://github.com/vega/ts-json-schema-generator | ||
export interface Annotations { | ||
[name: string]: any; | ||
} | ||
function getAnnotations(this: any, node: ts.Node): Annotations | undefined { | ||
const symbol: ts.Symbol = (node as any).symbol; | ||
if (!symbol) { | ||
return undefined; | ||
} | ||
|
||
const jsDocTags: ts.JSDocTagInfo[] = symbol.getJsDocTags(); | ||
if (!jsDocTags || !jsDocTags.length) { | ||
return undefined; | ||
} | ||
|
||
const annotations: Annotations = jsDocTags.reduce((result: Annotations, jsDocTag: ts.JSDocTagInfo) => { | ||
const value = this.parseJsDocTag(jsDocTag); | ||
if (value !== undefined) { | ||
result[jsDocTag.name] = value; | ||
} | ||
|
||
return result; | ||
}, {}); | ||
return Object.keys(annotations).length ? annotations : undefined; | ||
} | ||
|
||
// these examples are artificial and mostly nonsensical | ||
function parseSpecificTags(node: ts.Node) { | ||
if (node.kind === ts.SyntaxKind.Parameter) { | ||
return ts.getJSDocParameterTags(node as ts.ParameterDeclaration); | ||
} | ||
if (node.kind === ts.SyntaxKind.FunctionDeclaration) { | ||
const func = node as ts.FunctionDeclaration; | ||
if (ts.hasJSDocParameterTags(func)) { | ||
const flat: ts.JSDocTag[] = []; | ||
for (const tags of func.parameters.map(ts.getJSDocParameterTags)) { | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2495: Type '{ [x: number]: readonly JSDocParameterTag[]; hasTrailingComma?: readonly JSDocParameterTag[] | undefined; length: readonly JSDocParameterTag[]; toString: readonly JSDocParameterTag[]; toLocaleString: readonly JSDocParameterTag[]; concat: readonly JSDocParameterTag[]; join: readonly JSDocParameterTag[]; slice: readonly JSDocParameterTag[]; indexOf: readonly JSDocParameterTag[]; lastIndexOf: readonly JSDocParameterTag[]; every: readonly JSDocParameterTag[]; some: readonly JSDocParameterTag[]; forEach: readonly JSDocParameterTag[]; map: readonly JSDocParameterTag[]; filter: readonly JSDocParameterTag[]; reduce: readonly JSDocParameterTag[]; reduceRight: readonly JSDocParameterTag[]; pos: readonly JSDocParameterTag[]; end: readonly JSDocParameterTag[]; }' is not an array type or a string type. | ||
if (tags) flat.push(...tags); | ||
} | ||
return flat; | ||
} | ||
} | ||
} | ||
|
||
function getReturnTypeFromJSDoc(node: ts.Node) { | ||
if (node.kind === ts.SyntaxKind.FunctionDeclaration) { | ||
return ts.getJSDocReturnType(node); | ||
} | ||
let type = ts.getJSDocType(node); | ||
if (type && type.kind === ts.SyntaxKind.FunctionType) { | ||
return (type as ts.FunctionTypeNode).type; | ||
} | ||
} | ||
|
||
function getAllTags(node: ts.Node) { | ||
ts.getJSDocTags(node); | ||
} | ||
|
||
function getSomeOtherTags(node: ts.Node) { | ||
const tags: (ts.JSDocTag | undefined)[] = []; | ||
tags.push(ts.getJSDocAugmentsTag(node)); | ||
tags.push(ts.getJSDocClassTag(node)); | ||
tags.push(ts.getJSDocReturnTag(node)); | ||
const type = ts.getJSDocTypeTag(node); | ||
if (type) { | ||
tags.push(type); | ||
} | ||
tags.push(ts.getJSDocTemplateTag(node)); | ||
return tags; | ||
} | ||
|
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,36 @@ | ||
tests/cases/compiler/bestChoiceType.ts(3,23): error TS2349: This expression is not callable. | ||
Each member of the union type '(<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => { [x: number]: U; index?: U | undefined; input?: U | undefined; length: U; toString: U; toLocaleString: U; pop: U; push: U; concat: U; join: U; reverse: U; shift: U; slice: U; sort: U; splice: U; unshift: U; indexOf: U; lastIndexOf: U; every: U; some: U; forEach: U; map: U; filter: U; reduce: U; reduceRight: U; }) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])' has signatures, but none of those signatures are compatible with each other. | ||
tests/cases/compiler/bestChoiceType.ts(10,15): error TS2349: This expression is not callable. | ||
Each member of the union type '(<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => { [x: number]: U; index?: U | undefined; input?: U | undefined; length: U; toString: U; toLocaleString: U; pop: U; push: U; concat: U; join: U; reverse: U; shift: U; slice: U; sort: U; splice: U; unshift: U; indexOf: U; lastIndexOf: U; every: U; some: U; forEach: U; map: U; filter: U; reduce: U; reduceRight: U; }) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])' has signatures, but none of those signatures are compatible with each other. | ||
tests/cases/compiler/bestChoiceType.ts(16,15): error TS2349: This expression is not callable. | ||
Each member of the union type '(<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => { [x: number]: U; index?: U | undefined; input?: U | undefined; length: U; toString: U; toLocaleString: U; pop: U; push: U; concat: U; join: U; reverse: U; shift: U; slice: U; sort: U; splice: U; unshift: U; indexOf: U; lastIndexOf: U; every: U; some: U; forEach: U; map: U; filter: U; reduce: U; reduceRight: U; }) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])' has signatures, but none of those signatures are compatible with each other. | ||
|
||
|
||
==== tests/cases/compiler/bestChoiceType.ts (3 errors) ==== | ||
// Repro from #10041 | ||
|
||
(''.match(/ /) || []).map(s => s.toLowerCase()); | ||
~~~ | ||
!!! error TS2349: This expression is not callable. | ||
!!! error TS2349: Each member of the union type '(<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => { [x: number]: U; index?: U | undefined; input?: U | undefined; length: U; toString: U; toLocaleString: U; pop: U; push: U; concat: U; join: U; reverse: U; shift: U; slice: U; sort: U; splice: U; unshift: U; indexOf: U; lastIndexOf: U; every: U; some: U; forEach: U; map: U; filter: U; reduce: U; reduceRight: U; }) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])' has signatures, but none of those signatures are compatible with each other. | ||
|
||
// Similar cases | ||
|
||
function f1() { | ||
let x = ''.match(/ /); | ||
let y = x || []; | ||
let z = y.map(s => s.toLowerCase()); | ||
~~~ | ||
!!! error TS2349: This expression is not callable. | ||
!!! error TS2349: Each member of the union type '(<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => { [x: number]: U; index?: U | undefined; input?: U | undefined; length: U; toString: U; toLocaleString: U; pop: U; push: U; concat: U; join: U; reverse: U; shift: U; slice: U; sort: U; splice: U; unshift: U; indexOf: U; lastIndexOf: U; every: U; some: U; forEach: U; map: U; filter: U; reduce: U; reduceRight: U; }) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])' has signatures, but none of those signatures are compatible with each other. | ||
} | ||
|
||
function f2() { | ||
let x = ''.match(/ /); | ||
let y = x ? x : []; | ||
let z = y.map(s => s.toLowerCase()); | ||
~~~ | ||
!!! error TS2349: This expression is not callable. | ||
!!! error TS2349: Each member of the union type '(<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => { [x: number]: U; index?: U | undefined; input?: U | undefined; length: U; toString: U; toLocaleString: U; pop: U; push: U; concat: U; join: U; reverse: U; shift: U; slice: U; sort: U; splice: U; unshift: U; indexOf: U; lastIndexOf: U; every: U; some: U; forEach: U; map: U; filter: U; reduce: U; reduceRight: U; }) | (<U>(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any) => U[])' has signatures, but none of those signatures are compatible with each other. | ||
} | ||
|
Oops, something went wrong.