Are there any differences between "any" and "*"?

Viewed 16
1 Answers

Checking the sources of the Typescript compiler (The one that parses the JSDoc for typings) it shows that any, * (JSDoc ALL Type) and ? (JSDoc Unknown/ANY Type) are treated the same:

TypeScript/src/compiler/checker.ts

function getTypeFromTypeNodeWorker(node: TypeNode): Type {
    switch (node.kind) {
        case SyntaxKind.AnyKeyword:
        case SyntaxKind.JSDocAllType:
        case SyntaxKind.JSDocUnknownType:
            return anyType;
        // ...

Also, the logic for the Javascript to Typescript file transformer does the same:

TypeScript/src/services/codefixes/annotateWithTypeFromJSDoc.ts

function transformJSDocType(node: TypeNode): TypeNode {
    switch (node.kind) {
        case SyntaxKind.JSDocAllType:
        case SyntaxKind.JSDocUnknownType:
            return factory.createTypeReferenceNode("any", emptyArray);
        // ...
Related