[TypeScript] Ensure params not accept certain type
typescript not type params accept ENSURE
2023-09-14 08:59:12 时间
Let's say we have a function accept any type but array.
function anyTypesButNotArray<T>( val: T extends any[] ? "you should not pass in array" : T ) { return val; } anyTypesButNotArray(["sf", "sdf"]);
相关文章
- [Typescript 4.9] TypeScript 4.9: satisfies operator
- [Typescript] Approaches for Typing Object Parameters
- [Typescript] 39. Medium - AnyOf
- [Typescript] Convert a js project to typescript
- [TypeScript] Typescript Intersection & Union Types
- [Typescript] Dynamic types: Use TypeScript's Mapped Types and Template Literal Types Together
- [Typescript] Prevent Type Widening of Object Literals with TypeScript's const Assertions
- [Typescript] Statically Type Unknown Values with TypeScript's unknown Type
- [Typescript] Ignore Null or Undefined Values with TypeScript Non-Null Assertion Operator
- [Typescript] Understanding “lib” and ES libraries
- [Vue @Component] Extend Vue Components in TypeScript
- [TypeScript] Type check JavaScript files using JSDoc and Typescript 2.5
- [React Typescript 2022] Type a Radio Button Component in React using TypeScript
- [Typescript] Use the Optional Chaining Operator in TypeScript
- [Typescript] Improve Readability with TypeScript Numeric Separators when working with Large Numbers
- [VueJS + Typescript] Decouple Dependencies Using IoC Containers in Vue with TypeScript and InversifyJS
- [TypeScript@2.5] Omit catch error block if not needed
- [Algorithms] Binary Search Algorithm using TypeScript
- TypeScript constructor signature 类型的变量赋值方式
- TypeScript class 的静态成员变量
- Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported错误的多种解决方法及说明Content-Type