Comments (4)
This is a design limitation. Resolving of conditional types involving unbound generic types is deferred. The compiler does not know what type T
is, so it can't know what the conditional type resolves to.
from typescript.
Thanks!
cannot the fact that a base class for T (ItemContainer) is defined help in getting at least base class property types?
from typescript.
It'd be wrong to produce Item
here since T
might be instantiated with a class with a more-specific type in that field, e.g.
class Item {
name!: string
}
class SuperItem extends Item {
isSuper!: true;
}
abstract class ItemContainer {
items!: Item[]
}
class SuperItemContainer extends ItemContainer {
items!: SuperItem[];
}
class Drawer extends ItemContainer {
size!: number
}
type ArrayInnerType<A> = A extends (infer inferred)[] ? inferred : A;
class Manager<T extends ItemContainer> {
manage(object: T): ArrayInnerType<T["items"]> {
// Alleged: Should be just 'Item'
type wrongType = ArrayInnerType<T["items"]>;
// Then this is OK
const p: wrongType = new Item();
return p;
}
}
const p = new Manager<SuperItemContainer>();
// x: SuperItem, but it's actually an Item
const x = p.manage(new SuperItemContainer());
from typescript.
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
from typescript.
Related Issues (20)
- `tsc` compile `proposal-explicit-resource-management` different from `babel` and `swc` HOT 1
- After enabling noUncheckedIndexedAccess, using ++ on a default undefined does not trigger an error message. HOT 3
- C++-style `const` modifier on class members HOT 2
- Package Import is not working from neither way "CommonJS" or "Module" HOT 4
- Type guard for child not transitive parent object HOT 3
- Error when compiled JavaScript initializes static properties in a class with a hard private method (`#`) that references a static property
- The ?: inference failed; no selection was made between ifTrue and ifFalse. HOT 1
- Add Support for Flow's new component syntax HOT 6
- Documentation: "Creating and Printing a TypeScript AST" example does not work after v4.9.5
- `satisfies` does not work on a variable called `type`
- API: Can't seem to extract JsDoc tags from declaration HOT 2
- Add option to detect and strip internal exports
- false error on generic type alias parameters HOT 5
- Unable to declare an interface that extends `Record<string, nonAnyType>` with additional support functions. HOT 7
- Add support for generic types on a index accessor HOT 2
- `getTextOfJSDocComment` is stripping `#` from JSDoc comment HOT 1
- Enable `allowJs` with `isolatedDeclarations` HOT 1
- JSDoc comment string with the keyword "@private" before import statement in JS file result in cryptic error TS1191 during compilation HOT 2
- `NoInfer` isn't erased and breaks type narrowing HOT 3
- function with overloading incorrectly defines generic variables HOT 3
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.