Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript 5.1: ts.createLiteral is not a function #53077

Closed
johnnyreilly opened this issue Mar 3, 2023 · 2 comments
Closed

TypeScript 5.1: ts.createLiteral is not a function #53077

johnnyreilly opened this issue Mar 3, 2023 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@johnnyreilly
Copy link

johnnyreilly commented Mar 3, 2023

Bug Report

🔎 Search Terms

ts.createLiteral is not a function

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions 5.0 and 5.1

I noticed that the typescript@next test packs for ts-loader were failing with the esoteric error ts.createLiteral is not a function. I'm baffled as to why - so I thought I'd ask!

https://github.com/TypeStrong/ts-loader/actions/runs/4321988253/jobs/7543877954

image

💻 Code

// We can quickly address your report if:
//  - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!
//  - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.
//  - The incorrectness of the behavior is readily apparent from reading the sample.
// Reports are slower to investigate if:
//  - We have to pare too much extraneous code.
//  - We have to clone a large repo and validate that the problem isn't elsewhere.
//  - The sample is confusing or doesn't clearly demonstrate what's wrong.

https://github.com/TypeStrong/ts-loader/blob/9aa5b521a7647fdbd575bb76daa94183e3286604/test/execution-tests/loaderOptions/uppercaseStringLiteralTransformer.js#L10

"use strict";
exports.__esModule = true;
var ts = require("typescript");
var transformer = function (context) {
    var visitor = function (node) {
        if (node.kind === ts.SyntaxKind.StringLiteral) {
            var text = node.text;
            if (text.match(/^Hello from submodule/) !== null) {
                if (text !== text.toUpperCase()) {
                    return ts.createLiteral(text.toUpperCase());
                }
            }
        }
        return ts.visitEachChild(node, visitor, context);
    };
    return function (node) { return ts.visitNode(node, visitor); };
};
exports["default"] = transformer;

The tests make use of this API - ts-loader itself does not.

🙁 Actual behavior

Tests that usually pass now fail

🙂 Expected behavior

Tests that usually pass still pass

@RyanCavanaugh
Copy link
Member

This function has been marked deprecated since 4.1 (possibly earlier?)

https://github.com/microsoft/TypeScript/pull/52314/files#diff-c1d25c0f0add39e7c2e113b07a6214aacfd9538c89e0f8d9d055301c8d47eae6L1029

    /** @deprecated Use `factory.createStringLiteral`, `factory.createStringLiteralFromNode`, `factory.createNumericLiteral`, `factory.createBigIntLiteral`, `factory.createTrue`, `factory.createFalse`, or the factory supplied by your transformation context instead. */
    const createLiteral: {

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Mar 3, 2023
@johnnyreilly
Copy link
Author

Wowser! Thanks

johnnyreilly added a commit to TypeStrong/ts-loader that referenced this issue Mar 3, 2023
johnnyreilly added a commit to TypeStrong/ts-loader that referenced this issue Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants