Skip to content

"Extract to function" fails with "Error: Debug Failure. False expression."Β #44301

Closed
@OliverJAsh

Description

@OliverJAsh

Bug Report

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about refactorings

⏯ Playground Link

N/A

πŸ’» Code

interface UnionTypes<Record, TaggedRecord> {
    _Record: Record;
    _Union: TaggedRecord[keyof TaggedRecord];
}
declare type MultiValueRec = {
    [key: string]: {
        [tag: string]: any;
    };
};
declare function unionize<Record extends MultiValueRec>(
    record: Record,
): UnionTypes<
    Record,
    {
        [T in keyof Record]: Record[T];
    }
>;
declare const ofType: <T>() => T;

const ApplicationResponseOrPlaceholder = unionize({
    Response: ofType<{ data: {} }>(),
});
type ApplicationResponseOrPlaceholder =
    typeof ApplicationResponseOrPlaceholder._Union;

export const Application = ({
    responseOrPlaceholder,
    responseOption,
}: {
    responseOrPlaceholder: ApplicationResponseOrPlaceholder;
    responseOption:
        | typeof ApplicationResponseOrPlaceholder._Record['Response']
        | null;
}) => ({ responseOption, responseOrPlaceholder });
  1. Select { responseOption, responseOrPlaceholder }
  2. Run refactoring "extract to function in module scope"

image

πŸ™ Actual behavior

Refactoring fails

image

TS log contains error:

Info 133  [13:35:30.900] response:
    {"seq":0,"type":"response","command":"getApplicableRefactors","request_seq":24,"success":true,"body":[{"name":"Extract Symbol","description":"Extract function","actions":[{"description":"Extract to function in module scope","name":"function_scope_1","kind":"refactor.extract.function"}]}]}
Info 134  [13:35:30.902] request:
    {"seq":25,"type":"request","command":"getEditsForRefactor","arguments":{"file":"/Users/oliverash/Development/typescript-playground/src/main-ts.ts","startLine":34,"startOffset":8,"endLine":34,"endOffset":49,"refactor":"Extract Symbol","action":"function_scope_1"}}
Err 135   [13:35:30.917] Exception on executing command {"seq":25,"type":"request","command":"getEditsForRefactor","arguments":{"file":"/Users/oliverash/Development/typescript-playground/src/main-ts.ts","startLine":34,"startOffset":8,"endLine":34,"endOffset":49,"refactor":"Extract Symbol","action":"function_scope_1"}}:

    Debug Failure. False expression.

    Error: Debug Failure. False expression.
        at consumeTokenAndAdvanceScanner (/Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:136986:30)
        at processChildNodes (/Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:136956:33)
        at /Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:136848:21
        at visitNodes (/Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:28819:24)
        at Object.forEachChild (/Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:28955:24)
        at processNode (/Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:136845:20)
        at processChildNode (/Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:136916:21)
        at /Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:136846:21
        at visitNode (/Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:28814:24)
        at Object.forEachChild (/Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:28894:21)
        at processNode (/Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:136845:20)
        at processChildNode (/Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:136916:21)
        at processChildNodes (/Users/oliverash/Development/typescript-playground/node_modules/typescript/lib/tsserver.js:136963:48)

πŸ™‚ Expected behavior

The refactoring should work and create this function:

function newFunction(
    responseOption: { data: {} } | null,
    responseOrPlaceholder: { data: {} },
) {
    return { responseOption, responseOrPlaceholder };
}

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions