-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript Overview Digest #139
Comments
@ts-expect-error
ECMAScript Private Fieldsclass Person {
#name: string
constructor(name: string) {
this.#name = name;
}
greet() {
console.log(`Hello, my name is ${this.#name}!`);
}
}
let jeremy = new Person("Jeremy Bearimy");
jeremy.#name
// ~~~~~
// Property '#name' is not accessible outside class 'Person'
// because it has a private identifier. |
This typeRelated issue: microsoft/TypeScript#3694 example code: class Base {
handler?: <T extends this>(b: T) => void;
onSomeEvt(handler: (b: this) => void) {
this.handler = handler;
}
}
class Child extends Base {
init() {
this.onSomeEvt((c: Child) => {
c.work();
});
}
work() {
console.log("work");
}
} More complex realistic example: import TreeNode from "./TreeNode";
import cloneDeep from "lodash/cloneDeep";
import set from "lodash/set";
import { Dictionary } from "../../core/types";
import { Config, Model, ReactiveSetter, ITreeNode } from "./types";
export interface ModelPayload {
id: number | string;
type: string;
titleEn: string;
title: string;
}
interface Options extends Dictionary {
// Some framework like Vue need to manully trigger reactive change for value like Object|Array.
reactiveSetter?: ReactiveSetter;
}
export interface IRenderItem<T extends ModelPayload> extends ITreeNode<T> {
options: Options;
attrs: Dictionary;
isRenderItem: boolean;
id: number | string;
title: string;
type: string | number;
setAttr(keyPath: string, value: any): void;
clone<T extends this>(): T;
}
export default class RenderItem<T extends ModelPayload> extends TreeNode<T>
implements IRenderItem<T> {
options: Options;
/**
* Extra dataset. maybe we should use the name dataset, but for compatibility, we still use attrs.
*/
attrs: Dictionary;
constructor(config: Config, model: Model<T>, options?: Options) {
super(config, model);
this.options = options || {};
this.attrs = {};
}
get isRenderItem() {
return true;
}
get id() {
return this.model.id;
}
get title() {
if (this.options.locale == "en") {
return this.model.titleEn;
}
return this.model.title;
}
get type() {
return this.model.type;
}
setAttr(keyPath: string, value: any) {
set(this.attrs, keyPath, value);
if (this.options.reactiveSetter) {
this.options.reactiveSetter(this.attrs, keyPath, value);
}
}
// here ... 🍜
clone<C extends this>(/*options*/): C {
const cloned = new RenderItem(
this.config,
cloneDeep(this.model),
this.options
);
// this seemed important.
return cloned as C;
}
} And this: #138 (comment) |
"unknown" and "any" type
|
Module
|
Release notes
Posts
The text was updated successfully, but these errors were encountered: