Giter VIP home page Giter VIP logo

Comments (4)

MartinJohns avatar MartinJohns commented on May 25, 2024

such as the cases of inheritance

Inherited classes should not access private members. Removing the type is/was necessary for compatibility/implementation-hiding reasons: #38953 (comment)

This is somewhat a duplicate of #51489.

from typescript.

lsby avatar lsby commented on May 25, 2024

@MartinJohns

Alright, after reviewing the information you provided, I understand the complexity of this issue.

There are indeed several ways to address this problem, such as using protected or using a symbol to retain the type.

const xxx: unique symbol = Symbol()
class MyClass1<A> {
  declare [xxx]: A
  private a: A;
  constructor(a: A) {
    this.a = a
  }
}

However, one concern is that I test my code in ProjectA, everything works fine, but only after compiling, publishing, and then importing into ProjectB do I encounter the issue. This situation is troublesome because I have to go back and modify ProjectA.

Ideally, if such coding practices are not allowed, I would prefer to be notified of errors while writing ProjectA.

I expect consistency in behavior before and after code compilation.

from typescript.

snarbies avatar snarbies commented on May 25, 2024

So even though the property is private, it has observable structural implications that are lost in the generated typings.

Would the ideal be that private properties be hidden from inference machinery so that code like type X2 = MyClass2Sub<number> extends MyClass2<infer x> ? x : never would always yield never?

from typescript.

lsby avatar lsby commented on May 25, 2024

So even though the property is private, it has observable structural implications that are lost in the generated typings.

Would the ideal be that private properties be hidden from inference machinery so that code like type X2 = MyClass2Sub<number> extends MyClass2<infer x> ? x : never would always yield never?

Yes, I'd rather catch issues while writing code than discover them after publishing a package.

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.