Repository: microsoft/TypeScript
File: src/compiler/watchUtilities.ts (TypeScript)

Code before:
        hasSourceFile((filePathWithoutExtension + Extension.Tsx) as Path)
    ) {
        writeLog(`Project: ${configFileName} Detected output file: ${fileOrDirectory}`);
        return true;
    }
    return false;

    function hasSourceFile(file: Path): boolean {
        return realProgram ?
            !!realProgram.getSourceFileByPath(file) :
            builderProgram ?
            builderProgram.getState().fileInfos.has(file) :
            !!find(program as readonly string[], rootFile => toPath(rootFile) === file);
    }
}

function isBuilderProgram<T extends BuilderProgram>(program: Program | T): program is T {
    return !!(program as T).getState;
}

/** @internal */
export function isEmittedFileOfProgram(program: Program | undefined, file: string) {
    if (!program) {
        return false;
    }

    return program.isEmittedFile(file);
}

/** @internal */
export enum WatchLogLevel {
    None,
    TriggerOnly,
    Verbose,
}

/** @internal */
export interface WatchFactoryHost {
    watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number, options?: WatchOptions): FileWatcher;
    watchDirectory(path: string, callback: DirectoryWatcherCallback, recursive?: boolean, options?: WatchOptions): FileWatcher;
    getCurrentDirectory?(): string;
    useCaseSensitiveFileNames: boolean | (() => boolean);
}

/** @internal */
export interface WatchFactory<X, Y = undefined> {
    watchFile: (file: string, callback: FileWatcherCallback, pollingInterval: PollingInterval, options: WatchOptions | undefined, detailInfo1: X, detailInfo2?: Y) => FileWatcher;
    watchDirectory: (directory: string, callback: DirectoryWatcherCallback, flags: WatchDirectoryFlags, options: WatchOptions | undefined, detailInfo1: X, detailInfo2?: Y) => FileWatcher;
}

/** @internal */

Review comment (suggestion):
Should this fall back to `getScriptKindFromFileName` or something? If it's not provided, it seems like this returning false would make `isIgnoredFileFromWildCardWatching` always return true where it wouldn't have before?

(Doing that locally, nothing changed, so, maybe I don't know what I'm talking about)

Code after:
        return false;
    }

    // just check if sourceFile with the name exists
    const filePathWithoutExtension = removeFileExtension(fileOrDirectoryPath);
    const realProgram = isArray(program) ? undefined : isBuilderProgram(program) ? program.getProgramOrUndefined() : program;
    const builderProgram = !realProgram && !isArray(program) ? program as BuilderProgram : undefined;
    if (
        hasSourceFile((filePathWithoutExtension + Extension.Ts) as Path) ||
        hasSourceFile((filePathWithoutExtension + Extension.Tsx) as Path)
    ) {
        writeLog(`Project: ${configFileName} Detected output file: ${fileOrDirectory}`);
        return true;
    }
    return false;

    function hasSourceFile(file: Path): boolean {
        return realProgram ?
            !!realProgram.getSourceFileByPath(file) :
            builderProgram ?
            builderProgram.getState().fileInfos.has(file) :
            !!find(program as readonly string[], rootFile => toPath(rootFile) === file);
    }

    function isSupportedScriptKind() {
        if (!getScriptKind) return false;
        const scriptKind = getScriptKind(fileOrDirectory);
        switch (scriptKind) {
            case ScriptKind.TS:
            case ScriptKind.TSX:
            case ScriptKind.Deferred:
            case ScriptKind.External:
                return true;
            case ScriptKind.JS:
            case ScriptKind.JSX:
                return getAllowJSCompilerOption(options);
            case ScriptKind.JSON:
                return getResolveJsonModule(options);
            case ScriptKind.Unknown:
                return false;
        }
    }
}

function isBuilderProgram<T extends BuilderProgram>(program: Program | T): program is T {
    return !!(program as T).getState;
}

/** @internal */
export function isEmittedFileOfProgram(program: Program | undefined, file: string) {
    if (!program) {