Giter Site home page Giter Site logo

Comments (4)

Andarist avatar Andarist commented on June 2, 2024 1

It repros in the playground too: TS playground. To repro you need to hover over AssertionError. An interesting fact is that the first hover after a source edit triggers the error but the second one doesn't and it renders a good tooltip content.

from typescript.

Andarist avatar Andarist commented on June 2, 2024

Failing test case:

// @strict: true
// @moduleResolution: node
// @noEmit: true

// @filename: node_modules/@types/node/index.d.ts
/// <reference path="assert.d.ts" />
/// <reference path="assert/strict.d.ts" />

// @filename: node_modules/@types/node/assert/strict.d.ts
declare module "node:assert/strict" {
  import { strict } from "node:assert";
  export = strict;
}

// @filename: node_modules/@types/node/assert.d.ts
declare module "assert" {
  function assert(value: unknown, message?: string | Error): asserts value;
  namespace assert {
    class AssertionError extends Error {
      actual: unknown;
      expected: unknown;
      code: "ERR_ASSERTION";
      constructor(options?: {
        message?: string | undefined;
        actual?: unknown | undefined;
        expected?: unknown | undefined;
      });
    }

    namespace strict {
      type AssertionError = assert.AssertionError;
    }

    const strict: Omit<typeof assert, "strict">;
  }
  export = assert;
}
declare module "node:assert" {
  import assert = require("assert");
  export = assert;
}

// @filename: index.ts
import { AssertionError } from 'node:assert/strict';

throw new AssertionError({
  message: 'Hello',
  actual: 3,
  expected: 3,
});

from typescript.

jakebailey avatar jakebailey commented on June 2, 2024

The above test crashes even in TS 4.5 (and back even in 4.0 though with a slightly different error). So this most definitely is not a recent regression at all.

from typescript.

Andarist avatar Andarist commented on June 2, 2024

This is an interesting one. So the symbol that leads to a crash is a result of combineValueAndTypeSymbols. That combines a type symbol with a value symbol that is a mapped symbol. Mapped symbols don't have .valueDeclaration so there is nothing to attach onto the resulting combined symbol here. This leads to a crash.

We could propagate checkFlags here so getTypeOfSymbol could call getTypeOfMappedSymbol instead of getTypeOfVariableOrParameterOrProperty but that doesn't solve anything on its own. The combined symbol isn't truly a mapped symbol so it lacks properties that getTypeOfMappedSymbol expects.

I need to think more about it but it seems like more stuff should get propagated onto that combined symbol from the mapped symbol. getTypeOfSymbol here is interested in the type of the value and the value is typed using a mapped type... so - if I'm not mistaken - the only way to get the correct type is to resolve that mapped type symbol (we just can't do it right now since we lost the information required to do that along the way)

from typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.