yfain / getts Goto Github PK
View Code? Open in Web Editor NEWCode samples for the book TypeScript Quickly
License: MIT License
Code samples for the book TypeScript Quickly
License: MIT License
@yfain Errors!
> [email protected] start
> ng serve
(node:1350155) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2022-03-19T20:33:00.049Z
Hash: 19cdfdec1a616ee8cce4
Time: 5875ms
chunk {es2015-polyfills} es2015-polyfills.js, es2015-polyfills.js.map (es2015-polyfills) 285 kB [initial] [rendered]
chunk {main} main.js, main.js.map (main) 46.4 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 236 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.08 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 19.3 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3.8 MB [initial] [rendered]
ERROR in ./src/styles.scss (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded!./node_modules/sass-loader/lib/loader.js??ref--14-3!./src/styles.scss)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: Cannot find module 'node-sass'
Require stack:
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/sass-loader/lib/loader.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/loader-runner/lib/loadLoader.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/loader-runner/lib/LoaderRunner.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/webpack/lib/NormalModule.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/webpack/lib/NormalModuleFactory.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/webpack/lib/Compiler.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/webpack/lib/webpack.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular-devkit/build-webpack/src/webpack/index.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular-devkit/build-webpack/src/index.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular-devkit/build-angular/src/dev-server/index.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular-devkit/architect/src/architect-legacy.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular-devkit/architect/src/index.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular/cli/models/architect-command.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular/cli/commands/build-impl.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular-devkit/schematics/tools/export-ref.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular-devkit/schematics/tools/index.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular/cli/utilities/json-schema.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular/cli/models/command-runner.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular/cli/lib/cli/index.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular/cli/lib/init.js
- ~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/@angular/cli/bin/ng
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.sassLoader (~/Documents/WorkspaceJavaScript/forks/getts/chapter12/client/node_modules/sass-loader/lib/loader.js:46:72)
@yfain For now it's possible to have multiple genesis blocks on the client, due to not checking if generating genesis block is pending.
getts/chapter9/src/lib/universal_sha256.ts
const crypto = require('crypto');
The reference is written in the wrong place ,The reference should be written outside the function
In the example in Chapter 9, a third-party JavaScript module is imported (reused) in the TypeScript.
What about when you want to make your own separate modules in TypeScript?
I tried to extend the Chapter 9 code with a src/browser/a.ts
class that is simply
export class A { /* ... */ }
VS Code wants to import A using classic TypeScript syntax (just after the blockchain elements are imported):
import { Blockchain, Block } from '../lib/bc_transactions.js';
import { A } from 'a';
But when I run the code, I get a errors for importing a
-- first it requires a relative URL (so, I make it ./a
but then I get an error saying it's looking for a.js
).
Is there a clean solution in Chapter 9 for using TypeScript modules? It hardly feels realistic if all of the project is in main.ts
.
In the mean time, rather than using a bundler, I'll follow the advice of specifying .js
at the end of the import's specification microsoft/TypeScript#27287 (comment)
Warnings now
`WARNING in ~/router-product-list/src/product.ts
5:4 trailing whitespace
3 | title: string;
4 | price: number;
5 | }
| ^
WARNING in ~/router-product-list/src/product.ts
5:6 file should end with a newline
3 | title: string;
4 | price: number;
5 | }
| ^
WARNING in ~/router-product-list/src/views/Home.vue
39:3 The class property 'products' must be marked either 'private', 'public', or 'protected'
37 | export default class Home extends Vue {
38 |
39 | products: Product[]=[];
| ^
40 |
41 | selectedProduct: Product | null= null;
42 |
WARNING in ~/router-product-list/src/views/Home.vue
39:22 missing whitespace
37 | export default class Home extends Vue {
38 |
39 | products: Product[]=[];
| ^
40 |
41 | selectedProduct: Product | null= null;
42 |
WARNING in ~/router-product-list/src/views/Home.vue
39:23 missing whitespace
37 | export default class Home extends Vue {
38 |
39 | products: Product[]=[];
| ^
40 |
41 | selectedProduct: Product | null= null;
42 |
WARNING in ~/router-product-list/src/views/Home.vue
41:3 The class property 'selectedProduct' must be marked either 'private', 'public', or 'protected'
39 | products: Product[]=[];
40 |
41 | selectedProduct: Product | null= null;
| ^
42 |
43 | created() {
44 | fetch("/products.json")
WARNING in ~/router-product-list/src/views/Home.vue
41:34 missing whitespace
39 | products: Product[]=[];
40 |
41 | selectedProduct: Product | null= null;
| ^
42 |
43 | created() {
44 | fetch("/products.json")
WARNING in ~/router-product-list/src/views/Home.vue
43:3 The class method 'created' must be marked either 'private', 'public', or 'protected'
41 | selectedProduct: Product | null= null;
42 |
43 | created() {
| ^
44 | fetch("/products.json")
45 | .then(response => response.json())
46 | .then(json => {
WARNING in ~/router-product-list/src/views/Home.vue
44:11 " should be '
42 |
43 | created() {
44 | fetch("/products.json")
| ^
45 | .then(response => response.json())
46 | .then(json => {
47 | this.products=json;
WARNING in ~/router-product-list/src/views/Home.vue
45:11 Parentheses are required around the parameters of an arrow function definition
43 | created() {
44 | fetch("/products.json")
45 | .then(response => response.json())
| ^
46 | .then(json => {
47 | this.products=json;
48 | },
WARNING in ~/router-product-list/src/views/Home.vue
46:11 Parentheses are required around the parameters of an arrow function definition
44 | fetch("/products.json")
45 | .then(response => response.json())
46 | .then(json => {
| ^
47 | this.products=json;
48 | },
49 | (error) => {
WARNING in ~/router-product-list/src/views/Home.vue
47:20 missing whitespace
45 | .then(response => response.json())
46 | .then(json => {
47 | this.products=json;
| ^
48 | },
49 | (error) => {
50 | console.log('Error loading products.json:', error);
WARNING in ~/router-product-list/src/views/Home.vue
47:21 missing whitespace
45 | .then(response => response.json())
46 | .then(json => {
47 | this.products=json;
| ^
48 | },
49 | (error) => {
50 | console.log('Error loading products.json:', error);
WARNING in ~/router-product-list/src/views/Home.vue
50:8 Calls to 'console.log' are not allowed.
48 | },
49 | (error) => {
50 | console.log('Error loading products.json:', error);
| ^
51 | });
52 | }
53 |
No type errors found
Version: typescript 3.9.10, tslint 5.20.1`
In chapter 8 the name at the top of package.json states chapter 7
One more command line is needed in the chapter9 readme.
One more line is needed before npm start
.
$ npm run compileDeploy
This function needs to be corrected to properly calculate percentage based discounts.
function getFinalPrice(price: number, discount: number) {
//return price - price/discount;
return price - (price / 100) * discount; //CORRECTED
}
Error Source:
function calcTax(state: string, income: number, dependents: number) : number { 1
if (state === 'NY'){
return income * 0.06 - dependents * 500;
} else if (state ==='NJ'){
return income * 0.05 - dependents * 300;
}
}
1 The function arguments and its **return value** have type annotations.
The correct way is...
function calcTax(state: string, income: number, dependents: number) : number {
if (state === 'NY'){
return income * 0.06 - dependents * 500;
} else if (state ==='NJ'){
return income * 0.05 - dependents * 300;
}
return 0; // !!!!
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.