Skip to content

Allow type-checking when --isolatedModules specified: can PR for this change #613

@mheiber

Description

@mheiber

Expected behavior:

There is a way to get type-checking while using --isolatedModules

Actual behavior:

when passing --isolatedModules no type-checking is done. This is by design, but we want a way to get the same behavior as tsc, where --isolatedModules checks that separate compilation si safe, but doesn't actually do separate compilation.

Your gulpfile:

Include your gulpfile, or only the related task (with ts.createProject).

ts.createProject({ isolatedModules: true })

tsconfig.json

{
    "isolatedModules": true
}

Code

Include your TypeScript code, if necessary.

const x: string = 2; // should error

Suggestion Implementation: new GulpTsSettings with key useFileCompiler:

Happy to make a PR for this change. Sketch of implementation:

main.ts

export interface GulpTsSettings {
    useFileCompiler?: boolean
}
export function createProject(fileNameOrSettings?: string | Settings, settings?: Settings, gulpTsSettings: GulpTsSettings = {}): Project {
...
}

...

const project = _project.setupProject(projectDirectory, tsConfigFileName, rawConfig, tsConfigContent, compilerOptions, projectReferences, typescript, finalTransformers, gulpTsSettings.useFileCompiler);

project.ts

function setupProject(...useFileCompiler: boolean | undefined) {
    ...
    if (useFileCompiler && !options.isolatedModules) {
        throw Error("useFileCompiler: true can only be used if config.compilerOptions.isolatedModules is also set to true");
    }
    const compiler: ICompiler = (options.isolatedModules && (useFileCompiler === undefined || useFileCompiler === true)) ? new FileCompiler() : new ProjectCompiler();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions