enum TYPES {
CODE = 1,
TEXT,
IMAGE,
VIDEO
}
enum ALL_TYPES {
CODE = 1,
TEXT,
IMAGE,
VIDEO,
NONE
}
Is there a way to incorporate the TYPES enum into the ALL_TYPES enum?
enum TYPES {
CODE = 1,
TEXT,
IMAGE,
VIDEO
}
enum ALL_TYPES {
CODE = 1,
TEXT,
IMAGE,
VIDEO,
NONE
}
Is there a way to incorporate the TYPES enum into the ALL_TYPES enum?
As far as I know, there is ongoing consideration for extending enums, but in the meantime, you can utilize const objects instead:
const CATEGORIES = <const>{
FRUIT: 1,
VEGETABLE: 2,
MEAT: 3,
DAIRY: 4
};
const ALL_CATEGORIES = <const>{ ...CATEGORIES, NONE: 5 };
Various workarounds are also discussed in the aforementioned thread.
If you require type checking for this, note that a numeric enum
is essentially treated as a number
from a typing perspective:
enum CATEGORIES {
FRUIT,
VEGETABLE,
MEAT,
DAIRY
}
declare function processItem(name: string, type: string, category: CATEGORIES): any;
processItem('apple', 'fruit', CATEGORIES.FRUIT); // compiles
processItem('apple', 'fruit', 99); // also compiles (?)
If you opt to use an object as recommended above, you can enforce strict type checking by defining a type for all potential values of that object:
const CATEGORIES = <const>{
FRUIT: 1,
VEGETABLE: 2,
MEAT: 3,
DAIRY: 4
};
type CATEGORY_VALUE = typeof CATEGORIES[keyof typeof CATEGORIES]
declare function assignType(name: string, type: string, categoryValue: CATEGORY_VALUE): any;
assignType('apple', 'fruit', CATEGORIES.FRUIT); // compiles
assignType('apple', 'fruit', 99); // does not compile
Although slightly more verbose, this approach ensures proper type validation.
Is there a way to simulate multiple tab/window focus in a browser for testing purposes? I need to test pages that require user input and focus on active windows/tabs. Are there any different browsers, plugins, or JavaScript code that can help me achieve th ...
Recently, I conducted an experiment as part of my project. I utilized the ng-switch AngularJS directive to create a rendering condition. Here is the controller code: app.controller('MainCtrl', function($scope) { $scope.items = ['test1& ...
When I run CFSELECT normally it works fine, but when I try to include JavaScript inside it, I encounter an error. The normal version works as expected. <tr id='selectionDropdown'> <td >Non-Keyword Traffic:</td> <t ...
Is it possible to declare an array of type any[] where all elements are of the same type? For example: // Allowed const array1: any[] = [1, 2, 3]; const array2: any[] = ['a', 'b', 'c']; // Not allowed because it contains bot ...
After setting up the server-side code in app.js, I encountered an issue: console.log("Server started. If you're reading this then your computer is still alive."); //Unnecessary test command to make sure everything works. var express = require("expre ...
When forwarding innerRef to a styled-component like the example below, a type error occurs in typescript: interface MenuProps { isOpen: boolean } const BaseMenu = styled.ul<MenuProps>` padding: 0; /* ... styles ... */ ${({ isOpen }) => ...
Currently, I am working on a quiz application and have the final score stored in a function in app.js. My goal is to generate a bar graph visualization of the user's results (e.g. 6 right, 4 wrong) based on this score. To achieve this, I created anoth ...
Looking for a service that utilizes http requests? import { Injectable } from '@angular/core'; import { Observable, of } from 'rxjs'; import { HttpClient } from '@angular/common/http'; @Injectable({ providedIn: 'root&a ...
Click here for a guide on how to type the $store property. Unfortunately, I've been encountering issues with it. In my Vue 2 project created using vue-cliI, I included a vuex.d.ts file in ./src directory but the $store property in my components still ...
I am currently in the process of building an e-commerce platform website and I'm looking to implement a feature where users can add products to their cart with just a click of a button. However, before the product is added to the cart, I want to disp ...
As a beginner in Typescript, I am delving into creating a typed map structure where the values are associated with specific keys. This can be demonstrated through pseudo JS code without types: const propertyA = "PropertyA"; const propertyB = "PropertyB"; ...
Currently, I am faced with the challenge of placing my form on a slider in such a way that the slider appears to be running in the background of the form. When using position absolute, I find myself having to apply excessive margins and top pixels due to t ...
Recently, I have observed that a reference to an HTML element with an id can be easily accessed in JavaScript by using a variable named after that id (jsbin). What is the reason for this behavior? Why do we need to use getElementById(id) when we could sim ...
I need help figuring out how to post data to my "mail.py" script without knowing the URL link. Both my jQuery AJAX code and JavaScript file are located in RKProjects/scripts_js/contactform.js The Python script I want to connect to is stored in RKProjects ...
I've been working with an object data that looks like this: object = { "2020092020-08-01":{ "value":"123", "id_number":"202009" }, "2020092020-09-01":{ "value& ...
I am struggling with updating an array in Ionic2 and Angular2. I have tried updating it on the front end but it's not working, even though it updates perfectly on the backend (ts) as confirmed by checking the console. I need assistance with this. Her ...
I am currently dealing with multiple nested ng-repeats in my project, and the third level down consists of a group of checkboxes. Initially, I receive an array of options for these checkboxes, which I handle with the following code snippet: <div class= ...
I am currently utilizing the syncfusion ej2 Calendar plugin for a datepicker, but I am only using options such as selecting ranges like today, 1 month, or last 7 days from the plugin itself. The plugin provides dropdown options when the calendar is trigger ...
Update: Issue resolved, check out my answer below. The scenario: User interacts with a map-image google maps API V3 is loaded using ajax the map is displayed in a dialog window or lightbox What's going on: The map loads and all features are funct ...
var domEvents = new THREEx.DomEvents(camera, view.domElement); var div = document.createElement( 'div' ); div.setAttribute('data-remove','mesh1'); div.className = 'close-me'; var label = new THREE.CSS2DObje ...