Comments (4)
Conditional types are tricky as they often stay deferred in generic contexts. This version could somewhat easily work though (and it doesn't):
type StringKeys<T> = keyof {
[P in keyof T as T[P] extends string ? P & string : never]: any;
};
const bloop = <T,>(z: StringKeys<T>) => {
const f: string = z; // errors but shouldnt
};
As a workaround, you can use this version:
type StringKeys<T> = keyof {
[P in keyof T as T[P] extends string ? P : never]: any;
} &
string;
const bloop = <T,>(z: StringKeys<T>) => {
const f: string = z;
};
from typescript.
I would guess itβs just a matter of the compiler knowing that T & string
is always assignable to string
regardless of what T
is (by definition, as A & B
is the set of values assignable to both)
from typescript.
That workaround works in my real codebase, so I'll cut over to that approach for now - is this a matter of the intersection (instead of Extract
) causing non-deferred evaluation?
from typescript.
Bisects to #56742
from typescript.
Related Issues (20)
- [RFC] Code Prompts, a Prompt Format for AI-Powered Code Auto-Completion HOT 7
- Missing the `AbortSignal.any()` function
- Debug Failure. Did not expect ObjectLiteralExpression to have an Identifier in its trivia HOT 7
- Proposal - Module Interface HOT 6
- Uncaught Error: Debug Failure. at getThisContainer (while executing getCompletionsAtPosition n JavaScript file) HOT 1
- Support `satisfies` as a constraint on a function's generic type parameter HOT 22
- Type unexpectedly not narrowed after check
- Optional chaining for arrays inferring wrong type HOT 3
- TypeScript 5.4 import path completion results in unintended paths HOT 4
- Inconsistent Behavior with `readonly` in Template Literal Indexed Access Types HOT 3
- Design Meeting Notes, 4/2/2024
- Error: Debug Failure. False expression: Expected the specifier to be a default export HOT 1
- type assertions affect the type narrowing of the subsequent code HOT 6
- Missing interface definition for Highlight API HOT 1
- Improve new issue template selection - reorder and handle "this is crash" check better HOT 3
- Union type breaks type safety of dynamic object keys HOT 2
- Asserting changes type of original variable inline (the change reverts in subsequent lines) HOT 10
- "declare class" in a global is not visible in external files HOT 7
- Mapped type reported as incompatible when passed through another mapped type (5.4 regression) HOT 1
- Shorten error spans for missing key errors reported on object literals 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.