Using a full URL in a dynamic import()

ES2020 introduces a new function-like syntax for import, so-called “dynamic imports” permitting the dynamic import of JavaScript modules. The precise implementation of the importing process is left to the host (eg the browser, or Node.js), but modern web browsers do implement dynamic loading over HTTP using this syntax, with the module identified using a URL: … Read more

Unable to find any GraphQL type definitions for the following pointers: src/**/*.graphql

The file your shared is your schema (as generated by your server), but it seems that you haven’t created any queries or mutations on top of it. This would be a reason why the codegen is not working properly. I suggest thay you create a new file with a simple query, such as: get-users.query.graphql query … Read more

TypeScript return the type of parameter

There is. They are called generics. In your case this how it would look like: function foo<T>(bar: T): T { return bar; } var aString: string = foo(‘baz’); var aNumber: number = foo(6); T will be the generic parameter that will take whichever type is passed in bar. Also, you don’t have to explicitly specify … Read more

How do I read a local file in Deno?

(Update: wrapping code in async function main() { … } is no longer needed because Deno now supports top-level await) Using built-in Deno.readTextFile const countWords = (s: string): number => s.split(/\s+/g).filter(w => /[a-z0-9]/.test(w)).length; const text = await Deno.readTextFile(‘input.txt’); const count = countWords(text); console.log(`I read ${count} words.`); See the docs at: https://doc.deno.land/builtin/stable#Deno.readTextFile Using built-in Deno.readFile const … Read more

TypeScript Interface Function Property: What’s the difference?

1.) There is a difference between method and function property declaration: interface InterfaceA { doSomething(data: object): boolean; // method declaration } interface InterfaceB { doSomething: (data: object) => boolean; // function as property declaration } 2.) TypeScript 2.6 introduces a compiler flag for stronger-typed, sound function types: Under –strictFunctionTypes function type parameter positions are checked … Read more

Typescript: constants in an interface

You cannot declare values in an interface. You can declare values in a module: module OlympicMedal { export var GOLD = “Gold”; export var SILVER = “Silver”; } In an upcoming release of TypeScript, you will be able to use const: module OlympicMedal { export const GOLD = “Gold”; export const SILVER = “Silver”; } … Read more

TypeScript Partial type without undefined

TS 4.4 UPDATE: TS4.4 will have an –exactOptionalPropertyTypes compiler flag to give you the behavior you’re looking for directly with Partial, as long as you intentionally add undefined where you’d like to allow it: interface MyType { foo: string bar?: number | undefined // <– you want this } const merge = (value1: MyType, value2: … Read more

Is there code generation API for TypeScript?

Try ts-morph. Only been working with it for about an hour but it seems really capable. import {Project, Scope, SourceFile} from “ts-morph”; const project = new Project(); const sourceFile = project.createSourceFile(`./target/file.ts`); const classDeclaration = sourceFile.addClass({ name: ‘SomeClass’ }); const constr = classDeclaration.addConstructor({}); constr.setBodyText(‘this.myProp = myProp’); classDeclaration.addProperty({ name: ‘myProp’, type: ‘string’, initializer: ‘hello world!’, scope: Scope.Public … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)