Skip to content
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

Ignore __proto__ #13933

Open
Riim opened this issue Feb 7, 2017 · 4 comments
Open

Ignore __proto__ #13933

Riim opened this issue Feb 7, 2017 · 4 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@Riim
Copy link

Riim commented Feb 7, 2017

TypeScript Version: 2.2.0

Code:

{ __proto__: {} } as { [key: string]: string }

Expected behavior:
Ok

Actual behavior:
Type '{ __proto__: {}; }' cannot be converted to type '{ [key: string]: string; }'.

@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Feb 7, 2017
@felixfbecker
Copy link
Contributor

felixfbecker commented Feb 10, 2017

This is extremely annoying. Consider this

export const stepComponent = {
    bindings: {
        hasNextStep: '>',
        hasPreviousStep: '>',
        onNextStep: '&',
        onPreviousStep: '&'
    },
    controller: class StepController {
        public hasNextStep: boolean;
        public hasPreviousStep: boolean;
        public onNextStep: Function;
        public onPreviousStep: Function;
    }
};

angular.component('credentialsStep', {
    __proto__: stepComponent,
    bindings: {
        __proto__: stepComponent.bindings,
        user: '>'
    },
    controller: class CredentialsStepController extends stepComponent.controller {

        public credentialsForm: angular.IFormController;
        public user: any;
        public repeatedPassword: string;
    }
});

The credentialsComponent should be valid and have all properties of the stepComponent, instead it fails with

[ts]
Argument of type '{ __proto__: { bindings: { hasNextStep: string; hasPreviousStep: string; onNextStep: string; onPr...' is not assignable to parameter of type 'IComponentOptions'.
  Object literal may only specify known properties, and '__proto__' does not exist in type 'IComponentOptions'.

@jolexxa
Copy link

jolexxa commented Mar 6, 2019

Also ran into this tonight while making custom error subclasses for Node. Was expecting TypeScript to ignore anything relating to .__proto__ or at least have a mechanism for avoiding it.

class CustomError extends Error {
	constructor (message?: string) {
		// 'Error' breaks prototype chain here
		super(message);

		// restore prototype chain
		const actualProto = new.target.prototype;

		if (Object.setPrototypeOf) { Object.setPrototypeOf(this, actualProto); } else { this.__proto__ = actualProto; }
	}
}

Credits:
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget

https://stackoverflow.com/a/48342359

@exedor
Copy link

exedor commented May 31, 2020

Same here. I just ran into this using the following loop structure:

for (let i in qList) { qList[i].prop1.trim(); qList[i].prop2.trim(); }

It is a simple array of objects. The job of the loop is to iterate over all the objects and trim two of it's string properties. The documentation for typescript talks about iterating over the indexes of the array. The problem is after it's done doing that, the value of i changes from an index to 'contains' which is method on

__proto__

This is completely broke our application when we upgraded typescript to 2.9.2. It worked great on 1.8.

@mike-marcacci
Copy link

Just as a note, a full solution for this is described in this RFC: #38385.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
6 participants