Skip to content

API - DocumentRegistry - sourceFile.scriptTarget can possibly be undefined #26535

@dsherret

Description

@dsherret

Low priority issue, but the following is possible which can lead to errors when using the compiler API.

TypeScript Version: 3.1.0-dev.20180818

Search Terms: DocumentRegistry, languageVersion undefined

Code

import * as ts from "typescript";

const registry = ts.createDocumentRegistry();
const sourceFile = registry.acquireDocument("/file.ts", {}, ts.ScriptSnapshot.fromString(""), "1");

console.log(sourceFile.languageVersion); // undefined, but languageVersion is not nullable

Caused by the non-null assertion here.

Expected behavior: Not sure. Probably it should default to ScriptTarget.Latest or the compiler options should pass through the function that sets the default values.

Actual behavior: languageVersion is undefined because it was not set on the compiler options.

Related issues: Maybe #18217 covers this already.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions