Questions tagged [module-augmentation]
28 questions
8
votes
0 answers
Is a typescript module augmentation automatically exported in a component library?
I created a component library using material-ui and Typescript under the hood. I have used Typescript module augmentation in order to add new options to the theme, as described in their theme customization with Typescript documentation.
//…

Bassem
- 3,582
- 2
- 24
- 47
4
votes
2 answers
Typescript: Add a property on an inner object with module augmentation
Considering an external (npm) module extmod exposing the following interface in its declarations file:
interface Options {
somevar?: string;
suboptions?: {
somesubvar?: string;
};
}
How can I add a property somesubvar2 inside suboptions…

Zoddo
- 163
- 6
3
votes
0 answers
How can you add new variants to the Container component in MUI V5, using TS Module Augmentation?
I'm attempting to add a new variant to the Container component, directly in the ThemeOptions.
The documentation explains that we need to use module augmentation to extend the interface so that the ts compiler knows about the new prop we are…

Eric Crescioni
- 299
- 3
- 10
3
votes
0 answers
How to patch class constructor using typescript module augmentation?
I try to use typescript module augmentation in order to change this class in a module dependency :
// module/token_response.ts
export class TokenResponse {
accessToken: string;
constructor(response: TokenResponseJson) {
this.accessToken =…

vdeygas
- 41
- 2
2
votes
1 answer
Material UI theme module augmentation not working
I've been reading the MUI documentation, blogs, and other posts on Stackoverflow, yet despite all of that, I can't get my vscode intellisense/typescript to detect my changes.
They're very simple changes, quite similar to what many other examples…

kevin
- 2,707
- 4
- 26
- 58
2
votes
1 answer
Difficulty implementing Typescript Augmentation for my MUI theme
I have a custom theme with some additional key/values added to the theme. This is causing TS errors when I go to use the design tokens in my app. I know I need to use module augmentation to fix it but honestly I am so confused as to where this goes,…

Salvatore Argentieri
- 55
- 5
2
votes
0 answers
Extending global var in TypeScript
I'm trying to implement a Response.json static method polyfill. Response (not the interface, the class/constructor) is declared in lib.dom.d.ts. If it was defined with an interface like this:
declare var Response: ResponseConstructor;
interface…

cyco130
- 4,654
- 25
- 34
2
votes
0 answers
typescript module augmentation with inferred type
i hope someone can help me with this. I am creating a design system and therefor have 2 repos: the react component library and the application that consumes it. In the react library i am exporting a createTheme function which the application can use…

jarvispact
- 31
- 2
2
votes
3 answers
Material UI module augmentation across multiple packages in a monorepo
I am using lerna to create multiple UI packages.
I am augmenting @material-ui/styles in package a to add more palette and typography definitions.
I am able to get the new types in package a.
Package b is a component which uses material-ui's…

DiabolousL
- 31
- 1
- 3
2
votes
0 answers
Defining custom `ITheme` by overriding @material-ui's default `Theme` with module augmentation
Edit
This is what I ended up doing:
import { Theme } from '@material-ui/core/styles';
import { IPaletteOptions, PaletteOptions } from '@material-ui/core/styles/createPalette';
import { ClassNameMap, Styles, WithStylesOptions } from…

Mike K
- 7,621
- 14
- 60
- 120
2
votes
0 answers
Automatic augmentation of multiple packages
I am currently implementing a CMS that is based on different packages. It has a package for pages, core, files, etc...
At the core of it all is a simple service registry, basically like this:
interface Service {}
let registry: {[key: string]:…

apfelbox
- 2,625
- 2
- 24
- 26
1
vote
0 answers
Use module augmentation to change a function signature in TypeScript
I'm trying to override the a function signature defined in a TypeScript definition file, however I can't quite get it working. Below is the code that I have, but Typescript seems to be ignoring the augmentation, and is erroring saying that the…

Alexander Forbes-Reed
- 2,823
- 4
- 27
- 44
1
vote
1 answer
Typescript how to augment Object class?
I am familiar with the Kotlin extension function let (and related) (cf. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/let.html).
I wanted to use something similar in TypeScript, using augmentation (or is it called declaration merging?). So I…

fjf2002
- 872
- 5
- 15
0
votes
0 answers
How to extend jest namespace with a new function
I would like to extend jest namespace declared globally by adding a new custom spy-like function. The declaration seems to be accepted by the compiler but at run-time I am getting TypeError: jest.spyOnDispatchedActions is not a function
//…

avyarochkin
- 1
- 1
0
votes
0 answers
Add own custom Validator to registerOptions from react-hook-form
I'd like to add a custom validator to RegisterOptions from react-hook-form. Just like valueAsNumber and valueAsDate. I'd like to create it globally, so I have the option everywhere in my code. I'm using TypeScript. Now I'd like to use it like…

julian.a
- 1,163
- 2
- 9
- 21