mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
fix(29648): Error message related to JSDoc for non-JSDoc syntax error (#50793)
* fix(29648): improve diagnostics of non-JSDoc syntax errors * fix lint errors * update tests * change diagnostic type suggestion. fix QF for jsdoc nullable type * move error handling from the parser to the checker * change diagnostic message. remove speculative parsing * update baseline
This commit is contained in:
parent
ba393b6b9f
commit
44152bc22e
@ -43294,7 +43294,20 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
|
||||
function checkJSDocTypeIsInJsFile(node: Node): void {
|
||||
if (!isInJSFile(node)) {
|
||||
grammarErrorOnNode(node, Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments);
|
||||
if (isJSDocNonNullableType(node) || isJSDocNullableType(node)) {
|
||||
const token = tokenToString(isJSDocNonNullableType(node) ? SyntaxKind.ExclamationToken : SyntaxKind.QuestionToken);
|
||||
const diagnostic = node.postfix
|
||||
? Diagnostics._0_at_the_end_of_a_type_is_not_valid_TypeScript_syntax_Did_you_mean_to_write_1
|
||||
: Diagnostics._0_at_the_start_of_a_type_is_not_valid_TypeScript_syntax_Did_you_mean_to_write_1;
|
||||
const typeNode = node.type;
|
||||
const type = getTypeFromTypeNode(typeNode);
|
||||
grammarErrorOnNode(node, diagnostic, token, typeToString(
|
||||
isJSDocNullableType(node) && !(type === neverType || type === voidType)
|
||||
? getUnionType(append([type, undefinedType], node.postfix ? undefined : nullType)) : type));
|
||||
}
|
||||
else {
|
||||
grammarErrorOnNode(node, Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6545,6 +6545,14 @@
|
||||
"category": "Error",
|
||||
"code": 17018
|
||||
},
|
||||
"'{0}' at the end of a type is not valid TypeScript syntax. Did you mean to write '{1}'?": {
|
||||
"category": "Error",
|
||||
"code": 17019
|
||||
},
|
||||
"'{0}' at the start of a type is not valid TypeScript syntax. Did you mean to write '{1}'?": {
|
||||
"category": "Error",
|
||||
"code": 17020
|
||||
},
|
||||
"Circularity detected while resolving configuration: {0}": {
|
||||
"category": "Error",
|
||||
"code": 18000
|
||||
|
||||
@ -4809,7 +4809,6 @@ namespace Parser {
|
||||
if (contextFlags & NodeFlags.TypeExcludesFlags) {
|
||||
return doOutsideOfContext(NodeFlags.TypeExcludesFlags, parseType);
|
||||
}
|
||||
|
||||
if (isStartOfFunctionTypeOrConstructorType()) {
|
||||
return parseFunctionOrConstructorType();
|
||||
}
|
||||
|
||||
@ -809,12 +809,13 @@ export const enum NodeFlags {
|
||||
/** @internal */ PossiblyContainsDynamicImport = 1 << 21,
|
||||
/** @internal */ PossiblyContainsImportMeta = 1 << 22,
|
||||
|
||||
JSDoc = 1 << 23, // If node was parsed inside jsdoc
|
||||
JSDoc = 1 << 23, // If node was parsed inside jsdoc
|
||||
/** @internal */ Ambient = 1 << 24, // If node was inside an ambient context -- a declaration file, or inside something with the `declare` modifier.
|
||||
/** @internal */ InWithStatement = 1 << 25, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`)
|
||||
JsonFile = 1 << 26, // If node was parsed in a Json
|
||||
JsonFile = 1 << 26, // If node was parsed in a Json
|
||||
/** @internal */ TypeCached = 1 << 27, // If a type was cached for node at any point
|
||||
/** @internal */ Deprecated = 1 << 28, // If has '@deprecated' JSDoc tag
|
||||
/** @internal */ ConditionalTypeContext = 1 << 29,
|
||||
|
||||
BlockScoped = Let | Const,
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import {
|
||||
append,
|
||||
AsExpression,
|
||||
CallSignatureDeclaration,
|
||||
CodeFixAction,
|
||||
@ -10,6 +11,7 @@ import {
|
||||
GetAccessorDeclaration,
|
||||
getTokenAtPosition,
|
||||
IndexSignatureDeclaration,
|
||||
isJSDocNullableType,
|
||||
MappedTypeNode,
|
||||
MethodDeclaration,
|
||||
MethodSignature,
|
||||
@ -37,7 +39,12 @@ import {
|
||||
|
||||
const fixIdPlain = "fixJSDocTypes_plain";
|
||||
const fixIdNullable = "fixJSDocTypes_nullable";
|
||||
const errorCodes = [Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments.code];
|
||||
const errorCodes = [
|
||||
Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments.code,
|
||||
Diagnostics._0_at_the_end_of_a_type_is_not_valid_TypeScript_syntax_Did_you_mean_to_write_1.code,
|
||||
Diagnostics._0_at_the_start_of_a_type_is_not_valid_TypeScript_syntax_Did_you_mean_to_write_1.code,
|
||||
];
|
||||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions(context) {
|
||||
@ -51,7 +58,7 @@ registerCodeFix({
|
||||
if (typeNode.kind === SyntaxKind.JSDocNullableType) {
|
||||
// for nullable types, suggest the flow-compatible `T | null | undefined`
|
||||
// in addition to the jsdoc/closure-compatible `T | null`
|
||||
actions.push(fix(checker.getNullableType(type, TypeFlags.Undefined), fixIdNullable, Diagnostics.Change_all_jsdoc_style_types_to_TypeScript_and_add_undefined_to_nullable_types));
|
||||
actions.push(fix(type, fixIdNullable, Diagnostics.Change_all_jsdoc_style_types_to_TypeScript_and_add_undefined_to_nullable_types));
|
||||
}
|
||||
return actions;
|
||||
|
||||
@ -81,7 +88,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, ol
|
||||
function getInfo(sourceFile: SourceFile, pos: number, checker: TypeChecker): { readonly typeNode: TypeNode, readonly type: Type } | undefined {
|
||||
const decl = findAncestor(getTokenAtPosition(sourceFile, pos), isTypeContainer);
|
||||
const typeNode = decl && decl.type;
|
||||
return typeNode && { typeNode, type: checker.getTypeFromTypeNode(typeNode) };
|
||||
return typeNode && { typeNode, type: getType(checker, typeNode) };
|
||||
}
|
||||
|
||||
// TODO: GH#19856 Node & { type: TypeNode }
|
||||
@ -115,3 +122,15 @@ function isTypeContainer(node: Node): node is TypeContainer {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getType(checker: TypeChecker, node: TypeNode) {
|
||||
if (isJSDocNullableType(node)) {
|
||||
const type = checker.getTypeFromTypeNode(node.type);
|
||||
if (type === checker.getNeverType() || type === checker.getVoidType()) {
|
||||
return type;
|
||||
}
|
||||
return checker.getUnionType(
|
||||
append([type, checker.getUndefinedType()], node.postfix ? undefined : checker.getNullType()));
|
||||
}
|
||||
return checker.getTypeFromTypeNode(node);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/decorators/decoratorMetadata-jsdoc.ts(5,9): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/decorators/decoratorMetadata-jsdoc.ts(7,9): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/decorators/decoratorMetadata-jsdoc.ts(5,9): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
tests/cases/conformance/decorators/decoratorMetadata-jsdoc.ts(7,9): error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
tests/cases/conformance/decorators/decoratorMetadata-jsdoc.ts(9,9): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
|
||||
|
||||
@ -10,11 +10,11 @@ tests/cases/conformance/decorators/decoratorMetadata-jsdoc.ts(9,9): error TS8020
|
||||
@decorator()
|
||||
a?: string?;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
@decorator()
|
||||
b?: string!;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
@decorator()
|
||||
c?: *;
|
||||
~
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(9,21): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(10,20): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(11,21): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(12,23): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(12,24): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(10,20): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(11,21): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(12,23): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(12,24): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(14,28): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(15,27): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(16,28): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(17,30): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(17,31): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(15,27): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(16,28): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(17,30): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(17,31): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(19,21): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(20,20): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(21,21): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(22,23): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(22,24): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(20,20): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(21,21): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(22,23): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(22,24): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(24,28): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(25,27): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(26,28): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(27,30): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(27,31): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(25,27): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(26,28): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(27,30): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(27,31): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
|
||||
|
||||
==== tests/cases/compiler/expressionWithJSDocTypeArguments.ts (20 errors) ====
|
||||
@ -34,58 +34,58 @@ tests/cases/compiler/expressionWithJSDocTypeArguments.ts(27,31): error TS8020: J
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
const HuhFoo = foo<string?>;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
const NopeFoo = foo<?string>;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
const ComeOnFoo = foo<?string?>;
|
||||
~~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
|
||||
type TWhatFoo = typeof foo<?>;
|
||||
~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
type THuhFoo = typeof foo<string?>;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
type TNopeFoo = typeof foo<?string>;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
type TComeOnFoo = typeof foo<?string?>;
|
||||
~~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
|
||||
const WhatBar = Bar<?>;
|
||||
~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
const HuhBar = Bar<string?>;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
const NopeBar = Bar<?string>;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
const ComeOnBar = Bar<?string?>;
|
||||
~~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
|
||||
type TWhatBar = typeof Bar<?>;
|
||||
~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
type THuhBar = typeof Bar<string?>;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
type TNopeBar = typeof Bar<?string>;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
type TComeOnBar = typeof Bar<?string?>;
|
||||
~~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(2,15): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(4,15): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(4,15): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number | null | undefined'?
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(4,32): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(7,20): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(10,18): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
@ -7,12 +7,12 @@ tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(11,18): error TS255
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(13,14): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(14,11): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(15,8): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(16,11): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(17,17): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(16,11): error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(17,17): error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(18,5): error TS2322: Type 'undefined' is not assignable to type 'number | null'.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(18,17): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(20,16): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(21,16): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(18,17): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number | undefined'?
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(20,16): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number | null | undefined'?
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(21,16): error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(22,17): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(22,17): error TS802
|
||||
|
||||
function f(x: ?number, y: Array.<number>) {
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number | null | undefined'?
|
||||
~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
return x ? x + y[1] : y[0];
|
||||
@ -52,22 +52,22 @@ tests/cases/conformance/jsdoc/jsdocDisallowedInTypescript.ts(22,17): error TS802
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
var most: !string = 'definite';
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
var postfixdef: number! = 101;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
var postfixopt: number? = undefined;
|
||||
~~~~~~~~~~
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'number | null'.
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number | undefined'?
|
||||
|
||||
var nns: Array<?number>;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number | null | undefined'?
|
||||
var dns: Array<!number>;
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
var anys: Array<*>;
|
||||
~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
|
||||
@ -7,7 +7,7 @@ tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(8,22): erro
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(10,29): error TS5086: A labeled tuple element is declared as optional with a question mark after the name and before the colon, rather than after the type.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(12,46): error TS5087: A labeled tuple element is declared as rest with a '...' before the name, rather than before the type.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(14,49): error TS5087: A labeled tuple element is declared as rest with a '...' before the name, rather than before the type.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(14,52): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(14,52): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string[]'?
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(16,39): error TS5085: A tuple member cannot be both optional and rest.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(18,44): error TS2574: A rest element type must be an array type.
|
||||
tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(20,13): error TS2456: Type alias 'RecusiveRestUnlabeled' circularly references itself.
|
||||
@ -48,7 +48,7 @@ tests/cases/conformance/types/tuple/named/namedTupleMembersErrors.ts(21,13): err
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS5087: A labeled tuple element is declared as rest with a '...' before the name, rather than before the type.
|
||||
~~~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string[]'?
|
||||
|
||||
export type OptRest = [first: string, ...rest?: string[]]; // rest+optional disallowed
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(1,30): error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(5,30): error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(9,16): error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(10,16): error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(12,16): error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(13,16): error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(15,16): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(15,16): error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(16,16): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(16,16): error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(18,16): error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'any'?
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(19,10): error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(21,16): error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'any'?
|
||||
tests/cases/compiler/parseInvalidNonNullableTypes.ts(22,10): error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
|
||||
|
||||
==== tests/cases/compiler/parseInvalidNonNullableTypes.ts (14 errors) ====
|
||||
function f1(a: string): a is string! {
|
||||
~~~~~~~
|
||||
!!! error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
return true;
|
||||
}
|
||||
|
||||
function f2(a: string): a is !string {
|
||||
~~~~~~~
|
||||
!!! error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
return true;
|
||||
}
|
||||
|
||||
function f3(a: string!) {}
|
||||
~~~~~~~
|
||||
!!! error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
function f4(a: number!) {}
|
||||
~~~~~~~
|
||||
!!! error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
|
||||
function f5(a: !string) {}
|
||||
~~~~~~~
|
||||
!!! error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
function f6(a: !number) {}
|
||||
~~~~~~~
|
||||
!!! error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
|
||||
function f7(): string! {}
|
||||
~~~~~~~
|
||||
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
|
||||
~~~~~~~
|
||||
!!! error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
function f8(): !string {}
|
||||
~~~~~~~
|
||||
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
|
||||
~~~~~~~
|
||||
!!! error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string'?
|
||||
|
||||
const a = 1 as any!;
|
||||
~~~~
|
||||
!!! error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'any'?
|
||||
const b: number! = 1;
|
||||
~~~~~~~
|
||||
!!! error TS17019: '!' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
|
||||
const c = 1 as !any;
|
||||
~~~~
|
||||
!!! error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'any'?
|
||||
const d: !number = 1;
|
||||
~~~~~~~
|
||||
!!! error TS17020: '!' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number'?
|
||||
|
||||
43
tests/baselines/reference/parseInvalidNonNullableTypes.js
Normal file
43
tests/baselines/reference/parseInvalidNonNullableTypes.js
Normal file
@ -0,0 +1,43 @@
|
||||
//// [parseInvalidNonNullableTypes.ts]
|
||||
function f1(a: string): a is string! {
|
||||
return true;
|
||||
}
|
||||
|
||||
function f2(a: string): a is !string {
|
||||
return true;
|
||||
}
|
||||
|
||||
function f3(a: string!) {}
|
||||
function f4(a: number!) {}
|
||||
|
||||
function f5(a: !string) {}
|
||||
function f6(a: !number) {}
|
||||
|
||||
function f7(): string! {}
|
||||
function f8(): !string {}
|
||||
|
||||
const a = 1 as any!;
|
||||
const b: number! = 1;
|
||||
|
||||
const c = 1 as !any;
|
||||
const d: !number = 1;
|
||||
|
||||
|
||||
//// [parseInvalidNonNullableTypes.js]
|
||||
"use strict";
|
||||
function f1(a) {
|
||||
return true;
|
||||
}
|
||||
function f2(a) {
|
||||
return true;
|
||||
}
|
||||
function f3(a) { }
|
||||
function f4(a) { }
|
||||
function f5(a) { }
|
||||
function f6(a) { }
|
||||
function f7() { }
|
||||
function f8() { }
|
||||
var a = 1;
|
||||
var b = 1;
|
||||
var c = 1;
|
||||
var d = 1;
|
||||
@ -0,0 +1,51 @@
|
||||
=== tests/cases/compiler/parseInvalidNonNullableTypes.ts ===
|
||||
function f1(a: string): a is string! {
|
||||
>f1 : Symbol(f1, Decl(parseInvalidNonNullableTypes.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(parseInvalidNonNullableTypes.ts, 0, 12))
|
||||
>a : Symbol(a, Decl(parseInvalidNonNullableTypes.ts, 0, 12))
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function f2(a: string): a is !string {
|
||||
>f2 : Symbol(f2, Decl(parseInvalidNonNullableTypes.ts, 2, 1))
|
||||
>a : Symbol(a, Decl(parseInvalidNonNullableTypes.ts, 4, 12))
|
||||
>a : Symbol(a, Decl(parseInvalidNonNullableTypes.ts, 4, 12))
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function f3(a: string!) {}
|
||||
>f3 : Symbol(f3, Decl(parseInvalidNonNullableTypes.ts, 6, 1))
|
||||
>a : Symbol(a, Decl(parseInvalidNonNullableTypes.ts, 8, 12))
|
||||
|
||||
function f4(a: number!) {}
|
||||
>f4 : Symbol(f4, Decl(parseInvalidNonNullableTypes.ts, 8, 26))
|
||||
>a : Symbol(a, Decl(parseInvalidNonNullableTypes.ts, 9, 12))
|
||||
|
||||
function f5(a: !string) {}
|
||||
>f5 : Symbol(f5, Decl(parseInvalidNonNullableTypes.ts, 9, 26))
|
||||
>a : Symbol(a, Decl(parseInvalidNonNullableTypes.ts, 11, 12))
|
||||
|
||||
function f6(a: !number) {}
|
||||
>f6 : Symbol(f6, Decl(parseInvalidNonNullableTypes.ts, 11, 26))
|
||||
>a : Symbol(a, Decl(parseInvalidNonNullableTypes.ts, 12, 12))
|
||||
|
||||
function f7(): string! {}
|
||||
>f7 : Symbol(f7, Decl(parseInvalidNonNullableTypes.ts, 12, 26))
|
||||
|
||||
function f8(): !string {}
|
||||
>f8 : Symbol(f8, Decl(parseInvalidNonNullableTypes.ts, 14, 25))
|
||||
|
||||
const a = 1 as any!;
|
||||
>a : Symbol(a, Decl(parseInvalidNonNullableTypes.ts, 17, 5))
|
||||
|
||||
const b: number! = 1;
|
||||
>b : Symbol(b, Decl(parseInvalidNonNullableTypes.ts, 18, 5))
|
||||
|
||||
const c = 1 as !any;
|
||||
>c : Symbol(c, Decl(parseInvalidNonNullableTypes.ts, 20, 5))
|
||||
|
||||
const d: !number = 1;
|
||||
>d : Symbol(d, Decl(parseInvalidNonNullableTypes.ts, 21, 5))
|
||||
|
||||
57
tests/baselines/reference/parseInvalidNonNullableTypes.types
Normal file
57
tests/baselines/reference/parseInvalidNonNullableTypes.types
Normal file
@ -0,0 +1,57 @@
|
||||
=== tests/cases/compiler/parseInvalidNonNullableTypes.ts ===
|
||||
function f1(a: string): a is string! {
|
||||
>f1 : (a: string) => a is string
|
||||
>a : string
|
||||
|
||||
return true;
|
||||
>true : true
|
||||
}
|
||||
|
||||
function f2(a: string): a is !string {
|
||||
>f2 : (a: string) => a is string
|
||||
>a : string
|
||||
|
||||
return true;
|
||||
>true : true
|
||||
}
|
||||
|
||||
function f3(a: string!) {}
|
||||
>f3 : (a: string) => void
|
||||
>a : string
|
||||
|
||||
function f4(a: number!) {}
|
||||
>f4 : (a: number) => void
|
||||
>a : number
|
||||
|
||||
function f5(a: !string) {}
|
||||
>f5 : (a: string) => void
|
||||
>a : string
|
||||
|
||||
function f6(a: !number) {}
|
||||
>f6 : (a: number) => void
|
||||
>a : number
|
||||
|
||||
function f7(): string! {}
|
||||
>f7 : () => string
|
||||
|
||||
function f8(): !string {}
|
||||
>f8 : () => string
|
||||
|
||||
const a = 1 as any!;
|
||||
>a : any
|
||||
>1 as any! : any
|
||||
>1 : 1
|
||||
|
||||
const b: number! = 1;
|
||||
>b : number
|
||||
>1 : 1
|
||||
|
||||
const c = 1 as !any;
|
||||
>c : any
|
||||
>1 as !any : any
|
||||
>1 : 1
|
||||
|
||||
const d: !number = 1;
|
||||
>d : number
|
||||
>1 : 1
|
||||
|
||||
@ -0,0 +1,80 @@
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(1,30): error TS2677: A type predicate's type must be assignable to its parameter's type.
|
||||
Type 'string | null' is not assignable to type 'string'.
|
||||
Type 'null' is not assignable to type 'string'.
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(1,30): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(5,16): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(6,16): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number | undefined'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(8,16): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(9,16): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number | null | undefined'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(11,25): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(12,5): error TS2322: Type 'boolean' is not assignable to type 'string'.
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(15,16): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'any'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(16,10): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number | undefined'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(18,16): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'any'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(19,10): error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number | null | undefined'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(21,8): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'unknown'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(22,8): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'never'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(23,8): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'void'?
|
||||
tests/cases/compiler/parseInvalidNullableTypes.ts(24,8): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'undefined'?
|
||||
|
||||
|
||||
==== tests/cases/compiler/parseInvalidNullableTypes.ts (16 errors) ====
|
||||
function f1(a: string): a is ?string {
|
||||
~~~~~~~
|
||||
!!! error TS2677: A type predicate's type must be assignable to its parameter's type.
|
||||
!!! error TS2677: Type 'string | null' is not assignable to type 'string'.
|
||||
!!! error TS2677: Type 'null' is not assignable to type 'string'.
|
||||
~~~~~~~
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
return true;
|
||||
}
|
||||
|
||||
function f2(a: string?) {}
|
||||
~~~~~~~
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
function f3(a: number?) {}
|
||||
~~~~~~~
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number | undefined'?
|
||||
|
||||
function f4(a: ?string) {}
|
||||
~~~~~~~
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
function f5(a: ?number) {}
|
||||
~~~~~~~
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number | null | undefined'?
|
||||
|
||||
function f6(a: string): ?string {
|
||||
~~~~~~~
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
|
||||
return true;
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2322: Type 'boolean' is not assignable to type 'string'.
|
||||
}
|
||||
|
||||
const a = 1 as any?;
|
||||
~~~~
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'any'?
|
||||
const b: number? = 1;
|
||||
~~~~~~~
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number | undefined'?
|
||||
|
||||
const c = 1 as ?any;
|
||||
~~~~
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'any'?
|
||||
const d: ?number = 1;
|
||||
~~~~~~~
|
||||
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'number | null | undefined'?
|
||||
|
||||
let e: unknown?;
|
||||
~~~~~~~~
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'unknown'?
|
||||
let f: never?;
|
||||
~~~~~~
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'never'?
|
||||
let g: void?;
|
||||
~~~~~
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'void'?
|
||||
let h: undefined?;
|
||||
~~~~~~~~~~
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'undefined'?
|
||||
|
||||
47
tests/baselines/reference/parseInvalidNullableTypes.js
Normal file
47
tests/baselines/reference/parseInvalidNullableTypes.js
Normal file
@ -0,0 +1,47 @@
|
||||
//// [parseInvalidNullableTypes.ts]
|
||||
function f1(a: string): a is ?string {
|
||||
return true;
|
||||
}
|
||||
|
||||
function f2(a: string?) {}
|
||||
function f3(a: number?) {}
|
||||
|
||||
function f4(a: ?string) {}
|
||||
function f5(a: ?number) {}
|
||||
|
||||
function f6(a: string): ?string {
|
||||
return true;
|
||||
}
|
||||
|
||||
const a = 1 as any?;
|
||||
const b: number? = 1;
|
||||
|
||||
const c = 1 as ?any;
|
||||
const d: ?number = 1;
|
||||
|
||||
let e: unknown?;
|
||||
let f: never?;
|
||||
let g: void?;
|
||||
let h: undefined?;
|
||||
|
||||
|
||||
//// [parseInvalidNullableTypes.js]
|
||||
"use strict";
|
||||
function f1(a) {
|
||||
return true;
|
||||
}
|
||||
function f2(a) { }
|
||||
function f3(a) { }
|
||||
function f4(a) { }
|
||||
function f5(a) { }
|
||||
function f6(a) {
|
||||
return true;
|
||||
}
|
||||
var a = 1;
|
||||
var b = 1;
|
||||
var c = 1;
|
||||
var d = 1;
|
||||
var e;
|
||||
var f;
|
||||
var g;
|
||||
var h;
|
||||
56
tests/baselines/reference/parseInvalidNullableTypes.symbols
Normal file
56
tests/baselines/reference/parseInvalidNullableTypes.symbols
Normal file
@ -0,0 +1,56 @@
|
||||
=== tests/cases/compiler/parseInvalidNullableTypes.ts ===
|
||||
function f1(a: string): a is ?string {
|
||||
>f1 : Symbol(f1, Decl(parseInvalidNullableTypes.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(parseInvalidNullableTypes.ts, 0, 12))
|
||||
>a : Symbol(a, Decl(parseInvalidNullableTypes.ts, 0, 12))
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function f2(a: string?) {}
|
||||
>f2 : Symbol(f2, Decl(parseInvalidNullableTypes.ts, 2, 1))
|
||||
>a : Symbol(a, Decl(parseInvalidNullableTypes.ts, 4, 12))
|
||||
|
||||
function f3(a: number?) {}
|
||||
>f3 : Symbol(f3, Decl(parseInvalidNullableTypes.ts, 4, 26))
|
||||
>a : Symbol(a, Decl(parseInvalidNullableTypes.ts, 5, 12))
|
||||
|
||||
function f4(a: ?string) {}
|
||||
>f4 : Symbol(f4, Decl(parseInvalidNullableTypes.ts, 5, 26))
|
||||
>a : Symbol(a, Decl(parseInvalidNullableTypes.ts, 7, 12))
|
||||
|
||||
function f5(a: ?number) {}
|
||||
>f5 : Symbol(f5, Decl(parseInvalidNullableTypes.ts, 7, 26))
|
||||
>a : Symbol(a, Decl(parseInvalidNullableTypes.ts, 8, 12))
|
||||
|
||||
function f6(a: string): ?string {
|
||||
>f6 : Symbol(f6, Decl(parseInvalidNullableTypes.ts, 8, 26))
|
||||
>a : Symbol(a, Decl(parseInvalidNullableTypes.ts, 10, 12))
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const a = 1 as any?;
|
||||
>a : Symbol(a, Decl(parseInvalidNullableTypes.ts, 14, 5))
|
||||
|
||||
const b: number? = 1;
|
||||
>b : Symbol(b, Decl(parseInvalidNullableTypes.ts, 15, 5))
|
||||
|
||||
const c = 1 as ?any;
|
||||
>c : Symbol(c, Decl(parseInvalidNullableTypes.ts, 17, 5))
|
||||
|
||||
const d: ?number = 1;
|
||||
>d : Symbol(d, Decl(parseInvalidNullableTypes.ts, 18, 5))
|
||||
|
||||
let e: unknown?;
|
||||
>e : Symbol(e, Decl(parseInvalidNullableTypes.ts, 20, 3))
|
||||
|
||||
let f: never?;
|
||||
>f : Symbol(f, Decl(parseInvalidNullableTypes.ts, 21, 3))
|
||||
|
||||
let g: void?;
|
||||
>g : Symbol(g, Decl(parseInvalidNullableTypes.ts, 22, 3))
|
||||
|
||||
let h: undefined?;
|
||||
>h : Symbol(h, Decl(parseInvalidNullableTypes.ts, 23, 3))
|
||||
|
||||
63
tests/baselines/reference/parseInvalidNullableTypes.types
Normal file
63
tests/baselines/reference/parseInvalidNullableTypes.types
Normal file
@ -0,0 +1,63 @@
|
||||
=== tests/cases/compiler/parseInvalidNullableTypes.ts ===
|
||||
function f1(a: string): a is ?string {
|
||||
>f1 : (a: string) => a is string | null
|
||||
>a : string
|
||||
|
||||
return true;
|
||||
>true : true
|
||||
}
|
||||
|
||||
function f2(a: string?) {}
|
||||
>f2 : (a: string | null) => void
|
||||
>a : string | null
|
||||
|
||||
function f3(a: number?) {}
|
||||
>f3 : (a: number | null) => void
|
||||
>a : number | null
|
||||
|
||||
function f4(a: ?string) {}
|
||||
>f4 : (a: string | null) => void
|
||||
>a : string | null
|
||||
|
||||
function f5(a: ?number) {}
|
||||
>f5 : (a: number | null) => void
|
||||
>a : number | null
|
||||
|
||||
function f6(a: string): ?string {
|
||||
>f6 : (a: string) => string | null
|
||||
>a : string
|
||||
|
||||
return true;
|
||||
>true : true
|
||||
}
|
||||
|
||||
const a = 1 as any?;
|
||||
>a : any
|
||||
>1 as any? : any
|
||||
>1 : 1
|
||||
|
||||
const b: number? = 1;
|
||||
>b : number | null
|
||||
>1 : 1
|
||||
|
||||
const c = 1 as ?any;
|
||||
>c : any
|
||||
>1 as ?any : any
|
||||
>1 : 1
|
||||
|
||||
const d: ?number = 1;
|
||||
>d : number | null
|
||||
>1 : 1
|
||||
|
||||
let e: unknown?;
|
||||
>e : unknown
|
||||
|
||||
let f: never?;
|
||||
>f : null
|
||||
|
||||
let g: void?;
|
||||
>g : void | null
|
||||
|
||||
let h: undefined?;
|
||||
>h : null | undefined
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(3,22): error TS1257: A required element cannot follow an optional element.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(9,13): error TS2574: A rest element type must be an array type.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(10,13): error TS2574: A rest element type must be an array type.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(10,16): error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(10,16): error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(23,31): error TS2344: Type 'number[]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
Source provides no match for required element at position 0 in target.
|
||||
tests/cases/conformance/types/tuple/restTupleElements1.ts(24,31): error TS2344: Type '[]' does not satisfy the constraint '[number, ...number[]]'.
|
||||
@ -44,7 +44,7 @@ tests/cases/conformance/types/tuple/restTupleElements1.ts(59,4): error TS2345: A
|
||||
~~~~~~~~~~
|
||||
!!! error TS2574: A rest element type must be an array type.
|
||||
~~~~~~~
|
||||
!!! error TS8020: JSDoc types can only be used inside documentation comments.
|
||||
!!! error TS17019: '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'string | undefined'?
|
||||
type T10 = [string, ...[...string[]]];
|
||||
type T11 = [string, ...[...[...string[]]]];
|
||||
|
||||
|
||||
@ -378,6 +378,8 @@ Info 32 [00:01:13.000] response:
|
||||
"7027",
|
||||
"7028",
|
||||
"8020",
|
||||
"17019",
|
||||
"17020",
|
||||
"2774",
|
||||
"1308",
|
||||
"1103",
|
||||
@ -1708,6 +1710,8 @@ Info 38 [00:01:19.000] response:
|
||||
"7027",
|
||||
"7028",
|
||||
"8020",
|
||||
"17019",
|
||||
"17020",
|
||||
"2774",
|
||||
"1308",
|
||||
"1103",
|
||||
@ -2950,6 +2954,8 @@ Info 40 [00:01:21.000] response:
|
||||
"7027",
|
||||
"7028",
|
||||
"8020",
|
||||
"17019",
|
||||
"17020",
|
||||
"2774",
|
||||
"1308",
|
||||
"1103",
|
||||
|
||||
24
tests/cases/compiler/parseInvalidNonNullableTypes.ts
Normal file
24
tests/cases/compiler/parseInvalidNonNullableTypes.ts
Normal file
@ -0,0 +1,24 @@
|
||||
// @strict: true
|
||||
|
||||
function f1(a: string): a is string! {
|
||||
return true;
|
||||
}
|
||||
|
||||
function f2(a: string): a is !string {
|
||||
return true;
|
||||
}
|
||||
|
||||
function f3(a: string!) {}
|
||||
function f4(a: number!) {}
|
||||
|
||||
function f5(a: !string) {}
|
||||
function f6(a: !number) {}
|
||||
|
||||
function f7(): string! {}
|
||||
function f8(): !string {}
|
||||
|
||||
const a = 1 as any!;
|
||||
const b: number! = 1;
|
||||
|
||||
const c = 1 as !any;
|
||||
const d: !number = 1;
|
||||
26
tests/cases/compiler/parseInvalidNullableTypes.ts
Normal file
26
tests/cases/compiler/parseInvalidNullableTypes.ts
Normal file
@ -0,0 +1,26 @@
|
||||
// @strict: true
|
||||
|
||||
function f1(a: string): a is ?string {
|
||||
return true;
|
||||
}
|
||||
|
||||
function f2(a: string?) {}
|
||||
function f3(a: number?) {}
|
||||
|
||||
function f4(a: ?string) {}
|
||||
function f5(a: ?number) {}
|
||||
|
||||
function f6(a: string): ?string {
|
||||
return true;
|
||||
}
|
||||
|
||||
const a = 1 as any?;
|
||||
const b: number? = 1;
|
||||
|
||||
const c = 1 as ?any;
|
||||
const d: ?number = 1;
|
||||
|
||||
let e: unknown?;
|
||||
let f: never?;
|
||||
let g: void?;
|
||||
let h: undefined?;
|
||||
@ -4,8 +4,8 @@
|
||||
//// }
|
||||
|
||||
verify.codeFix({
|
||||
description: "Change 'number?' to 'number | null'",
|
||||
errorCode: 8020,
|
||||
description: "Change 'number?' to 'number | undefined'",
|
||||
errorCode: 17019,
|
||||
index: 0,
|
||||
newRangeContent: "number | null",
|
||||
newRangeContent: "number | undefined",
|
||||
});
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
//// }
|
||||
|
||||
verify.codeFix({
|
||||
description: "Change 'string?' to 'string | null | undefined'",
|
||||
errorCode: 8020,
|
||||
description: "Change 'string?' to 'string | undefined'",
|
||||
errorCode: 17019,
|
||||
index: 1,
|
||||
newRangeContent: "string | null | undefined",
|
||||
newRangeContent: "string | undefined",
|
||||
});
|
||||
|
||||
@ -3,8 +3,8 @@
|
||||
//// var x = 12 as [|number?|];
|
||||
|
||||
verify.codeFix({
|
||||
description: "Change 'number?' to 'number | null'",
|
||||
errorCode: 8020,
|
||||
description: "Change 'number?' to 'number | undefined'",
|
||||
errorCode: 17019,
|
||||
index: 0,
|
||||
newRangeContent: "number | null",
|
||||
newRangeContent: "number | undefined",
|
||||
});
|
||||
|
||||
@ -2,8 +2,16 @@
|
||||
//// var f = <[|function(number?): number|]>(x => x);
|
||||
|
||||
verify.codeFix({
|
||||
description: "Change 'function(number?): number' to '(arg0: number) => number'",
|
||||
description: "Change 'number?' to 'number'",
|
||||
errorCode: 17019,
|
||||
index: 0,
|
||||
newRangeContent: "function(number): number",
|
||||
applyChanges: true
|
||||
});
|
||||
|
||||
verify.codeFix({
|
||||
description: "Change 'function(number): number' to '(arg0: number) => number'",
|
||||
errorCode: 8020,
|
||||
index: 0,
|
||||
newRangeContent: "(arg0: number | null) => number",
|
||||
newRangeContent: "(arg0: number) => number",
|
||||
});
|
||||
|
||||
11
tests/cases/fourslash/codeFixChangeJSDocSyntax27.ts
Normal file
11
tests/cases/fourslash/codeFixChangeJSDocSyntax27.ts
Normal file
@ -0,0 +1,11 @@
|
||||
// @strict: true
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// function f(x: [|never?|]) {
|
||||
//// }
|
||||
|
||||
verify.codeFix({
|
||||
description: "Change 'never?' to 'never'",
|
||||
errorCode: 17019,
|
||||
index: 0,
|
||||
newRangeContent: "never",
|
||||
});
|
||||
11
tests/cases/fourslash/codeFixChangeJSDocSyntax28.ts
Normal file
11
tests/cases/fourslash/codeFixChangeJSDocSyntax28.ts
Normal file
@ -0,0 +1,11 @@
|
||||
// @strict: true
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// function f(x: [|void?|]) {
|
||||
//// }
|
||||
|
||||
verify.codeFix({
|
||||
description: "Change 'void?' to 'void'",
|
||||
errorCode: 17019,
|
||||
index: 0,
|
||||
newRangeContent: "void",
|
||||
});
|
||||
@ -3,8 +3,8 @@
|
||||
//// var x: [|?number|] = 12;
|
||||
|
||||
verify.codeFix({
|
||||
description: "Change '?number' to 'number | null'",
|
||||
errorCode: 8020,
|
||||
description: "Change '?number' to 'number | null | undefined'",
|
||||
errorCode: 17020,
|
||||
index: 0,
|
||||
newRangeContent: "number | null",
|
||||
newRangeContent: "number | null | undefined",
|
||||
});
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
//// var x: [|number?|] = 12;
|
||||
|
||||
verify.codeFix({
|
||||
description: "Change 'number?' to 'number | null | undefined'",
|
||||
description: "Change 'number?' to 'number | undefined'",
|
||||
index: 1,
|
||||
newRangeContent: "number | null | undefined",
|
||||
newRangeContent: "number | undefined",
|
||||
});
|
||||
|
||||
@ -6,5 +6,5 @@
|
||||
verify.codeFixAll({
|
||||
fixId: "fixJSDocTypes_plain",
|
||||
fixAllDescription: "Change all jsdoc-style types to TypeScript",
|
||||
newFileContent: "function f(a: number | null, b: string) {}",
|
||||
newFileContent: "function f(a: number | null | undefined, b: string) {}",
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user