Comments (2)
You can just define your own utility type like type OrElse<A, B, C> = [A] extends [B] ? A : C
and use that. TS is unlikely to add new syntax if utility types can serve the same purpose, even if you'd prefer to see A extends B ?? C
and not OrElse<A, B, C>
.
Also, bikeshedding syntax: ??
doesn't seem to have the same meaning in your suggestion as it does in JS. Where is the "nullishness" here? Maybe if B
is {}
? I'd expect a type like A??C
to evaluate to A
unless it is nullish, and then C
otherwise, so that string ?? number
is string
, but null ?? number
is number
. Since that's not what you're suggesting, the particular syntax would be misleading.
from typescript.
To not repeat yourself, you can use infer R extends
as a workaround. Not sure what your real-world code looks like but this may work.
type Foo<T> = Bar<
[Some<Really<Deep<Complex<Type<Utility<T>>>>>>] extends [infer R extends readonly unknown[]]
? R
: never
>;
from typescript.
Related Issues (20)
- Template Literal Type JSX children prop issue HOT 2
- [isolatedDeclarations] Add a syntactic form of computed property name which is always emitted as a computed property name HOT 5
- "Move to file" on global code unnecessarily imports/exports, generates invalid code HOT 3
- Wrong type on when using logical operators in nested conditions HOT 3
- Narrowing for constant indexed access fails on array getter HOT 3
- Design Meeting Notes, 6/7/2024 HOT 6
- Typescript 5.5 performance regression on arktype HOT 2
- Assertion violation in "move to new file"
- [nightly] Syntactically invalid declaration files emitted under extremely specific conditions HOT 1
- Make TypeScript Compilable to Native Machine Code! HOT 4
- [NewErrors] 5.6.0-dev.20240609 vs 5.4.5 HOT 58
- [ServerErrors][JavaScript] 5.6.0-dev.20240609 HOT 14
- [ServerErrors][TypeScript] 5.6.0-dev.20240609 HOT 24
- Special member completions not work after a comment.
- Module resolution: ESM-style namespace importing is broken HOT 5
- getSpecifierForModuleSymbol failing in 5.5 rc HOT 3
- Typescript process is consuming much memory and preventing suggestions at editor HOT 2
- Ignored tsconfig when targeting file HOT 2
- Control flow analysis for element access with variable index doesn't account for async race condition HOT 7
- URLSearchParams not accept number as a value 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.