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

Cannot create rest type from generic type #23246

Closed
neoncom opened this issue Apr 7, 2018 · 3 comments
Closed

Cannot create rest type from generic type #23246

neoncom opened this issue Apr 7, 2018 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@neoncom
Copy link

neoncom commented Apr 7, 2018

TypeScript Version: 2.8.1 (vs code newest)

Search Terms: rest parameter destructuring generic

Code

error_ts

Expected behavior: no error (because TA extends A, and A is an object, and rest parameters should work with objects...).

It worked with ts 2.7.2, but NOT with 2.8.1

Actual behavior: see pic

Playground Link: http://www.typescriptlang.org/play/index.html#src=interface%20A%20%7B%7D%0D%0A%0D%0Aclass%20MyClass%3CTA%20extends%20A%3E%7B%0D%0A%20%20%20%20method()%20%7B%0D%0A%20%20%20%20%20%20%20%20const%20a%3A%20A%20%3D%20null%20as%20any%3B%0D%0A%20%20%20%20%20%20%20%20const%20%7B%20...props1%20%7D%20%3D%20a%3B%0D%0A%20%20%20%20%20%20%20%20const%20ab%3A%20TA%20%3D%20null%20as%20any%3B%0D%0A%0D%0A%0D%0A%0D%0A%20%20%20%20%20%20%20%20const%20%7B%20...props2%20%7D%20%3D%20ab%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A

Related Issues:

@MartinJohns
Copy link
Contributor

MartinJohns commented Apr 7, 2018

because TA extends A, and A is an object

A doesn't has to be an object.

interface A { }
const a1: A = 5;
const a2: A = true;

It worked with ts 2.7.2

I just tested it with version 2.7.2, and your code does not work there either.

Also it seems to be a duplicate of #10727 and will hopefully someday be implemented with #13288.

@neoncom
Copy link
Author

neoncom commented Apr 7, 2018

1. interface A { bla: 3; } does not work either. and that is an object. If something extends that interface, it is an object, too. So yes, it is a bug :)
2. it worked with ts 2.7.1. 2.7.2 was incorrect,. sorry.

and:

interface {}

can be an object, but

interface { property:number; }

must be an object. did not believe it. but it is true. you're right

a novice would just a assume that case 1 is an object without a property. and i am no novice (in TS)

for me something like this can be an object:

{ prop: number; } | number | string

I'm gonna post my tsconfig, just in case it you test it in 2.7.1 and it work's there too (it shoud not)

{
	"extends": "../tsconfig.base",
	"compileOnSave": true,
	"compilerOptions": {
		"allowSyntheticDefaultImports": true, // for shallowequal package
		"module": "esnext",
		"lib": [
			"es2015",
			"dom",
			"esnext.asynciterable"
		],
		"stripInternal": true,
		"forceConsistentCasingInFileNames": true,
		"experimentalDecorators": true,
		"outDir": "../build",
		"noEmitHelpers": true,
		"importHelpers": true,
		"jsx": "react",
		"typeRoots": [
			"../../node_modules/@types",
			"../types"
		],
		"baseUrl": ".",
		"paths": {
			"@components/*": [
				"components/*"
			],
			"@lib/*": [
				"lib/*"
			],
			"@common/*": [
				"common/*"
			],
			"@redux/*": [
				"redux/*"
			],
			"@services/*": [
				"services/*"
			],
			"@translations/*": [
				"translations/*"
			],
			"@serverApi/*": [
				"server-api/*"
			]
		},
		"strictFunctionTypes": false
	},
	"include": [
		"**/*.ts",
		"**/*.tsx"
	]
}

it extends this:

{
    "compilerOptions": {
        "strict": true,
        "moduleResolution": "node",
        "removeComments": true,
        "target": "ES6"
    }
}

@mhegazy mhegazy added the Duplicate An existing issue was already created label Apr 9, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants