Comments (4)
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.
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.
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.
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 yieldnever
?
Yes, I'd rather catch issues while writing code than discover them after publishing a package.
from typescript.
Related Issues (20)
- [transpileDeclaration API][5.5] Self referencing generic type constraint with union gets emitted as `unknown`
- tsc crash with `Error: start < 0` in a specific config HOT 1
- computeCommonSourceDirectory doesn't work with subst on windows
- Type union not matched starting from TS 5.1 HOT 3
- union with `any` shows as union in signature quickinfo but `any` in parameter quickinfo HOT 5
- Add strictFunctionTypes to Enhance Type Safety for Function Parameters HOT 3
- Methods of classes extended in others do not inherit the types of method arguments. HOT 3
- TypeScript colorizer confused by comments after colon in class member function signature with Generic return type HOT 1
- More flexible handling of circular types with "typeof function" inference HOT 4
- If statement return type with union inferred incorrectly HOT 4
- Compiler cannot handle promise.then(null | undefined)
- Meta: Normative Changes for Explicit Resource Management
- Declaration emit does not remember the names it assigned to certain type parameters
- Nullish coalescing operator but for conditional types HOT 2
- Function generic unmatched: Matching hehavior is difference between arrow functions and normal function
- Method `concat` has wrong typization HOT 3
- Invalid type inference for optional chaining operator when nullish check is extracted to `const` varaiable HOT 2
- Inline type annotations for destructured properties using angle bracket syntax HOT 3
- Enum generic does not restrict union of possible objects where enum is defined HOT 8
- `const wrong = () => (1 < 3) as true // type: () => true` this should be an error. HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.