[Typescript] OVerride external library Types
typescript library types External override
2023-09-14 08:59:11 时间
import { getAnimatingState } from "fake-animation-lib";
import { Equal, Expect } from "../helpers/type-utils";
const animatingState = getAnimatingState();
type tests = [
Expect<
Equal<
typeof animatingState,
"before-animation" | "animating" | "after-animation"
>
>
];
Current the function getAnimatingState
return is just string
type. And it is coming from a extranal library fake-animation-lib
.
export const getAnimatingState = (): string => {
if (Math.random() > 0.5) {
return "before-animation";
}
if (Math.random() > 0.5) {
return "animating";
}
return "after-animation";
};
The way to override is by create a new *.d.ts
file, you name name the file as you want, but need to keep .d.ts
// the new *.d.ts will override the previous declarion file
declare module "fake-animation-lib" {
export type AnimatingState = "before-animation" | "animating" | "after-animation"
export function getAnimatingState(): AnimatingState;
}
相关文章
- [Typescript] Inferring Literal Types from any Basic Type
- [Typescript] Creating Chainable Method Abstractions with Generics and the Builder Pattern - 05
- [Typescript 4.9] TypeScript 4.9: satisfies operator
- [Typescript] @typescript-eslint/unbound-method
- [Typescript]106. Medium - OnPropChangedMethods
- [Typescript] The naked type
- [Typescript] 69. Medium - Trim Right
- [TypeScript] Variadic Tuple Types V4 ...T
- [TypeScript] AssertType
- [Typescript] Use the Nullish Coalescing Operator in TypeScript (isNil)
- [Typescript] Exclude Properties from a Type in TypeScript (Omit)
- [Typescript Challenges] 144 Hard - Transpose
- [Typescript] OVerride external library Types
- [Typescript] Declaring Globals for a Library
- [Typescript] Create a Union of Strings with All Possible Permutations of Two Unions
- [Typescript] Function scope in typescript
- [Typescript] 68. Medium - Fill
- [!Typescript] Tips: Access deeper parts of objects and arrays
- [Typescript] Extract & Exclude
- [Typescript] Making TypeScript Stick - 5 - Extends
- [Typescript] Making TypeScript Stick - 3
- [Typescript] Use the Optional Chaining Operator in TypeScript
- [Typescript] Extend Functionality of a TypeScript Class with Decorators
- [TypeScript] @OnChange for ngOnChanges