Skip to content

NumericLiteral nodes with value 9007199254740993 claim to have .text = 9007199254740992 #33298

Description

TypeScript Version: 3.7.0-dev.20190907

Search Terms: numeric literal max value 9007199254740992 9007199254740993

Code

const ts = require("typescript");
const sourceFile = ts.createSourceFile("temp.ts", "9007199254740993", 99);
const literal = sourceFile.statements[0].expression;

// '9007199254740992'
console.log("Actual .text:", literal.text);

// '9007199254740993'
console.log("Expected .text:", literal.getText(sourceFile));

Expected behavior:

.text should be the direct textual representation of the literal's value, right?

Actual behavior:

...some kind of rounding behavior related to being above Number.MAX_SAFE_INTEGER?

Playground Link: https://astexplorer.net/#/gist/8ee21b9bb7973f0d0118658496cec5ec/9dcea811268d39e678732414b53d608e37747a63 - since this is an AST parser issue

Related Issues: Discovered while writing a codefix for #29863. 😆

Activity

  1. JoshuaKGoldberg commented on Sep 7, 2019

    @JoshuaKGoldberg
    ContributorAuthor

    Did a little bit of digging. This happens in checkBigIntSuffix (in scanner.ts):

    : +tokenValue;

    Removing that + fixes the issue. Happy to send a PR if this is desirable!

  2. lowr commented on Dec 3, 2021

    @lowr
    Contributor

    I found this issue while fixing #46195. Looking at the explanation for the text property of LiteralLikeNode (link), it seems like it is actually working as intended. I'm not sure it’s always been like so since when this issue was opened, though.

    I could argue that the property name text is confusing as one would expect it to be the node's textual representation in the source code.

  3. RyanCavanaugh commented on Mar 4, 2024

    @RyanCavanaugh
    Member

    Agreed this is operating as documented.

  4. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions