I have some qbs project and I've met with some strange behavior of linking with runtime library.
I used Qt static libraries and custom modules
//---------MyQtGuiApplication.qbs
import qbs
MyQtApplication {
Depends { name: "Qt.gui" }
Depends {
name: "Qt"
submodules: Qt.gui.defaultQpaPlugin
condition: linkDefaultQpaPlugin && Qt.gui.defaultQpaPlugin
}
property bool linkDefaultQpaPlugin: Qt.gui.isStaticLibrary
}
//---------MyQtApplication.qbs
import qbs
MyNativeBinary {
type: ["application"]
Depends { name: "Qt.core" }
}
//---------MyNativeBinary.qbs
import qbs
import qbs.Environment
NativeBinary {
Depends { name: "cpp" }
property bool err: console.error(name + "______" + cpp.runtimeLibrary)
}
And simple example
//---------test.qbs
import qbs
Project {
MyQtGuiApplication {
name: "test"
Depends { name: "cpp" }
// cpp.runtimeLibrary: "static"
files: ["*.h", "*.cpp", "*.ui", "*.qrc", "*.rc"]
}
}
I clearly defined profiles.windows-x86-msvc14.cpp.runtimeLibrary: "static", and it isn't override by inheritance or qbs files. But if I dont define it in qbs files, I get
error LNK2038: mismatch detected for 'RuntimeLibrary'
I'd like to save modularity and not duplicate this parameter.
Have you any idea, why is this happening?
Related
I have a "library framework" nested inside my Next.js project (for now, as I don't want to go through the process of making it a standalone package yet). In that project I declare a few types, interfaces, and variables in one module, and then I try to override one of the interfaces from outside that module at the top-level of my app. So I have basically this:
components/
styles.ts // define interface here
package.d.ts // override module interface here
In package.d.ts I have this:
type AppFont = {
amharic: true
arabic: true
armenian: true
bengali: true
burmese: true
chinese: true
georgian: true
hebrew: true
hindi: true
inuktitut: true
japanese: true
kannada: true
khmer: true
korean: true
latin: true
malayalam: true
persian: true
tamil: true
text: true
thai: true
tibetan: true
}
declare module './components/styles' {
interface Font extends AppFont {}
}
In component/styles.ts I have this (amongst other variables and types):
export interface Font {
arial: true
}
export interface Theme {}
Also in my outer app I have this:
import { Font } from 'components/styles'
const fonts: Record<keyof Font, string> = {
amharic: 'Amharic',
arabic: 'Arabic',
armenian: 'Armenian',
bengali: 'Bengali',
burmese: 'Burmese',
chinese: 'Chinese',
georgian: 'Georgian',
hebrew: 'Hebrew',
hindi: 'Hindi',
inuktitut: 'Inuktitut',
japanese: 'Japanese',
kannada: 'Kannada',
khmer: 'Khmer',
korean: 'Korean',
latin: 'Latin',
malayalam: 'Malayalam',
persian: 'Persian',
tamil: 'Tamil',
text: 'text',
thai: 'Thai',
tibetan: 'Tibetan',
}
export const theme = {
fonts
}
export type AppTheme = typeof theme
So my final attempt at module override in package.d.ts looks like this:
declare module './components/styles' {
interface Font extends AppFont {}
interface Theme extends AppTheme {}
}
I then have a component like this inside the "nested library" (components/MyComponent.tsx):
type ComponentPropsType = {
font: keyof Font
}
export default function Component({
font,
}: ComponentPropsType) {
...
}
Since this component is in the library, it only has access to arial font. But since I overrode it, it should now accept all the fonts in the list. However, I am getting an error when I try and reference "tamil" font for example. So it's not picking it up.
What am I doing wrong? I am referencing the links here.
I'm trying to utilize the Lightbox component from Gatsby Starter Lightbox to display a few image galleries on different pages.
As the starter component is setup by default, it only supports one directory of images, as set in gatsby-config.js
`gatsby-plugin-styled-components`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `cars`,
path: `${__dirname}/src/images/cars/`,
},
Then in pages/index.js it passes the Lightbox component all of the images.
<Lightbox images={data.allImageSharp.edges} />
allImageSharp {
edges {
node {
sizes(maxWidth: 1800) {
...GatsbyImageSharpSizes
}
}
}
}
So I'm trying to figure out how to provide it a custom set of images, based on different image directories.
I'm new to Gatsby and React and couldn't figure out how to filter allImageSharp by directory, but I did figure out a way with allFile...though I ran into a type error trying to use it.
What I tried:
gallery: allFile(filter: {relativeDirectory: {eq: "screenshots/producta"}, extension: {regex: "/(jpg)|(png)/"}}) {
edges {
node {
id
name
relativeDirectory
extension
}
}
}
But in trying to utilize that with:
<Lightbox images={props.data.gallery} />
I got the error "TypeError: images.map is not a function"
So I think I may have figured it out. What I've done appears to be working, but I would caution that I don't know how "right" or good of a solution it is.
I seemed to have been on a working path earlier in my question, but had a few things off.
Here's what I've done:
I updated my query so it would return childImageSharp for each node, so now it's returning the equivalent of what was being returned in with allImageSharp from the starter pack. However, this structure is slightly different, so I also had to update the Lightbox.js component to properly reference these changes. You'll notice that my query has a subfield called 'fluid', instead of 'sizes'. This is because I noticed 'sizes' is deprecated in Gatsby 2.x. Fluid appears to return the same fields though. So I updated 'sizes' to 'fluid' everywhere it was referenced in Lightbox.js.
<Lightbox images={props.data.gallery.edges} />
gallery: allFile(
filter: {
relativeDirectory: { eq: "screenshots/producta" }
extension: { regex: "/(jpg)|(png)/" }
}
) {
edges {
node {
id
name
relativeDirectory
extension
childImageSharp {
fluid {
base64
tracedSVG
aspectRatio
src
srcSet
srcWebp
srcSetWebp
sizes
originalImg
originalName
presentationWidth
presentationHeight
}
}
}
}
}
It's entirely possible to resolve several paths with gatsby-source-filesystem:
{
resolve: `gatsby-source-filesystem`,
options: {
name: `cars`,
path: `${__dirname}/src/images/cars/`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `productScreenshots`,
path: `${__dirname}/src/screenshots/products/`,
},
},
Notice the name property? It could be used to query exactly that subset:
query getCarImages {
allFile(
filter: {sourceInstanceName: {eq: "cars"}}
) {
nodes {
childImageSharp {
fluid {
...
}
}
}
}
}
Alternatively, you can dump all your images into src/images, point plugin at it once and then filter based on subdirectories' paths as mentioned in your examples.
I have created an editor using Slate js in react.
I am trying to insert a block at the end of the editor content.
I came across a method to insert block at the range. How to specify the range of the document such that my custom blocks gets added at the end of the content but focus stays at the current selection and not at the end of the document.
function insertFile(editor, src, target) {
editor.insertBlock({
type: 'file',
data: { src },
})
}
My schema looks like this
const schema = {
blocks: {
file:{
isVoid: true
}
}
}
Using the Transforms object, it behaves just like you wished.
import { Transforms } from 'slate'
Transforms.insertNodes(
editor,
{ type: 'paragraph', children: [{ text: 'xxxx' }] },
{ at: [editor.children.length] }
)
To see the document for this: Link1 Link2
Since I have begin to learn Angular 2 , I am following the basic concepts well. But when I tried running the below program, I don't get the values which is statically set in the code.
import { Component,Input } from '#angular/core';
export class Hero {
id: number;
name: string;
}
hero: Hero = {
id: 1,
name: 'Windstorm'
};
#Component({
selector: 'my-app',
template: '<h1>{{title}}</h1><h2>{{hero.name}} details!</h2><div><label>id: </label>{{hero.id}}</div><div><label>name: </label>{{hero.name}}</div>'
})
export class AppComponent {
title = 'Tour of Heroes';
hero = 'Windstorm';
}
Can someone please point out where I am wrong, also can someone show how to debug the Angular code so that I can learn the framework well and try complex things out by self-learning and solve out basic issues by myself?
The output which I got
This should work
#Component({
selector: 'my-app',
template: '<h1>{{title}}</h1><h2>{{hero.name}} details!</h2><div><label>id: </label>{{hero.id}}</div><div><label>name: </label>{{hero.name}}</div>'
})
export class AppComponent {
title = 'Tour of Heroes';
hero: Hero = {
id: 1,
name: 'Windstorm'
};
}
With hero = 'Windowstorm'; {{hero.name}} is invalid because hero doesn't have a name property.
I'm sure your browser console show an error message. Please add such errors to future questions.
I have some JavaScript code that uses objects as dictionaries; for example a 'person' object will hold a some personal details keyed off the email address.
var people = {<email> : <'some personal data'>};
adding > "people[<email>] = <data>;"
getting > "var data = people[<email>];"
deleting > "delete people[<email>];"
Is it possible to describe this in Typescript? or do I have to use an Array?
In newer versions of typescript you can use:
type Customers = Record<string, Customer>
In older versions you can use:
var map: { [email: string]: Customer; } = { };
map['foo#gmail.com'] = new Customer(); // OK
map[14] = new Customer(); // Not OK, 14 is not a string
map['bar#hotmail.com'] = 'x'; // Not OK, 'x' is not a customer
You can also make an interface if you don't want to type that whole type annotation out every time:
interface StringToCustomerMap {
[email: string]: Customer;
}
var map: StringToCustomerMap = { };
// Equivalent to first line of above
In addition to using an map-like object, there has been an actual Map object for some time now, which is available in TypeScript when compiling to ES6, or when using a polyfill with the ES6 type-definitions:
let people = new Map<string, Person>();
It supports the same functionality as Object, and more, with a slightly different syntax:
// Adding an item (a key-value pair):
people.set("John", { firstName: "John", lastName: "Doe" });
// Checking for the presence of a key:
people.has("John"); // true
// Retrieving a value by a key:
people.get("John").lastName; // "Doe"
// Deleting an item by a key:
people.delete("John");
This alone has several advantages over using a map-like object, such as:
Support for non-string based keys, e.g. numbers or objects, neither of which are supported by Object (no, Object does not support numbers, it converts them to strings)
Less room for errors when not using --noImplicitAny, as a Map always has a key type and a value type, whereas an object might not have an index-signature
The functionality of adding/removing items (key-value pairs) is optimized for the task, unlike creating properties on an Object
Additionally, a Map object provides a more powerful and elegant API for common tasks, most of which are not available through simple Objects without hacking together helper functions (although some of these require a full ES6 iterator/iterable polyfill for ES5 targets or below):
// Iterate over Map entries:
people.forEach((person, key) => ...);
// Clear the Map:
people.clear();
// Get Map size:
people.size;
// Extract keys into array (in insertion order):
let keys = Array.from(people.keys());
// Extract values into array (in insertion order):
let values = Array.from(people.values());
You can use templated interfaces like this:
interface Map<T> {
[K: string]: T;
}
let dict: Map<number> = {};
dict["one"] = 1;
You can use Record for this:
https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkt
Example (A mapping between AppointmentStatus enum and some meta data):
const iconMapping: Record<AppointmentStatus, Icon> = {
[AppointmentStatus.Failed]: { Name: 'calendar times', Color: 'red' },
[AppointmentStatus.Canceled]: { Name: 'calendar times outline', Color: 'red' },
[AppointmentStatus.Confirmed]: { Name: 'calendar check outline', Color: 'green' },
[AppointmentStatus.Requested]: { Name: 'calendar alternate outline', Color: 'orange' },
[AppointmentStatus.None]: { Name: 'calendar outline', Color: 'blue' }
}
Now with interface as value:
interface Icon {
Name: string
Color: string
}
Usage:
const icon: SemanticIcon = iconMapping[appointment.Status]
You can also use the Record type in typescript :
export interface nameInterface {
propName : Record<string, otherComplexInterface>
}
Lodash has a simple Dictionary implementation and has good TypeScript support
Install Lodash:
npm install lodash #types/lodash --save
Import and usage:
import { Dictionary } from "lodash";
let properties : Dictionary<string> = {
"key": "value"
}
console.log(properties["key"])